Android - 获取SD卡的内存空间大小

获取SD卡的内存空间大小

 1        //获得SD卡空间的信息

 2         File path=Environment.getExternalStorageDirectory();

 3         StatFs statFs=new StatFs(path.getPath());

 4         long blocksize=statFs.getBlockSize();

 5         long totalblocks=statFs.getBlockCount();

 6         long availableblocks=statFs.getAvailableBlocks();

 7         

 8         //计算SD卡的空间大小

 9         long totalsize=blocksize*totalblocks;

10         long availablesize=availableblocks*blocksize;

11         

12         //转化为可以显示的字符串

13         String totalsize_str=Formatter.formatFileSize(this, totalsize);

14         String availablesize_strString=Formatter.formatFileSize(this, availablesize);

 

 

你可能感兴趣的:(android)