当前位置: 代码迷 >> Android >> Android下获取手机跟SD卡的总空间和可用空间
  详细解决方案

Android下获取手机跟SD卡的总空间和可用空间

热度:43   发布时间:2016-04-28 04:45:34.0
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);

  相关解决方案