首页 > 代码库 > Android下获取手机和SD卡的总空间和可用空间
Android下获取手机和SD卡的总空间和可用空间
获取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);
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。