如何计算本地存储空间?

时间:2011-06-19 15:26:32

标签: android local-storage space

如何在本地存储上找到剩余/总空间?

我可以使用StatF(如 - How to Check available space on android device ? on SD card?

1 个答案:

答案 0 :(得分:2)

原来你可以。抛出这段代码,它似乎返回了我内部存储器中剩余的适当字节数。不确定Environment.getDataDirectory()

的可靠性
public static long remainingLocalStorage()
{
    StatFs stat = new StatFs(Environment.getDataDirectory().getPath());
    stat.restat(Environment.getDataDirectory().getPath());
    long bytesAvailable = (long)stat.getBlockSize() *(long)stat.getAvailableBlocks();
    return bytesAvailable;
}