这是我的代码,
private String memSize(String path){
StatFs stat = new StatFs(path);
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
long freeBlocks = stat.getFreeBlocks();
long countBlocks = stat.getBlockCount();
String fileSize = Formatter.formatFileSize(this, availableBlocks * blockSize);
String maxSize = Formatter.formatFileSize(this, countBlocks * blockSize);
String info = path.toString()
+ "\nblockSize : " + Long.toString(blockSize)
+ "\navailableBlocks : " + Long.toString(availableBlocks)
+ "\nfreeBlocks : " + Long.toString(freeBlocks)
+ "\nreservedBlocks : " + Long.toString(freeBlocks - availableBlocks)
+ "\ncountBlocks : " + Long.toString(countBlocks)
+ "\nspace : " + fileSize + " / " + maxSize
+ "\n\n";
return info;
}
我使用路径/data
和/sdcard
来测试我的功能,并且它可以正常工作
但是当path为/
时(我知道它是根路径),这就是结果。
我认为根路径是SuperUser区域。可能需要一些许可才能访问 我的手机已经扎根了。你能告诉我下一步该做什么吗?
谢谢。
参考文献