标签:android
获取SD卡的总空间和可用空间
File path = Environment.getExternalStorageDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long totalBlocks = stat.getBlockCount(); long availableBlocks = stat.getAvailableBlocks(); long totalSize = totalBlocks * blockSize; long availSize = availableBlocks * blockSize; String totalStr = Formatter.formatFileSize(this, totalSize); String availStr = Formatter.formatFileSize(this, availSize);
File path2 = Environment.getDataDirectory(); StatFs stat2 = new StatFs(path2.getPath()); long blockSize2 = stat2.getBlockSize(); long totalBlocks2 = stat2.getBlockCount(); long availableBlocks2 = stat2.getAvailableBlocks(); long totalSize2 = totalBlocks2 * blockSize2; long availSize2 = availableBlocks2 * blockSize2; String totalStr2 = Formatter.formatFileSize(this, totalSize2); String availStr2 = Formatter.formatFileSize(this, availSize2);
Android下获取手机和SD卡的总空间和可用空间,布布扣,bubuko.com
标签:android
原文地址:http://blog.csdn.net/feecooling/article/details/37879473