码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2014-07-18 21:22:16      阅读:247      评论:0      收藏:0      [点我收藏+]

标签: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下获取手机和SD卡的总空间和可用空间

标签:android

原文地址:http://blog.csdn.net/feecooling/article/details/37879473

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!