gpt4 book ai didi

java - Android 内存使用情况

转载 作者:太空宇宙 更新时间:2023-11-04 14:07:08 25 4
gpt4 key购买 nike

我是 Android 新手,我想在内部存储中找到可用内存。我使用两个函数来查找可用内存,但它们以长格式显示两个不同的值。我不知道为什么?这是我的代码:

1) getTIM()函数的结果是558628864

public String getTIM(){
File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long totalBlocks = stat.getBlockCount();
String str = Long.toString(blockSize * totalBlocks);
return str;
}

2) ITMStr()函数的结果是914120704

public String ITMStr(){
StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
long blockCount = statFs.getBlockCountLong();
long blockSize = statFs.getBlockSizeLong();
long total = blockCount * blockSize;
String str = Long.toString(total);
return str;
}

哪个值是正确的?

最佳答案

根据reference :

public static File getDataDirectory ()

Added in API level 1 Return the user data directory.

_

public static File getRootDirectory ()

Added in API level 1 Return root of the "system" partition holding the core Android OS. Always present and mounted read-only.

因此,当您获得不同元素的尺寸时,尺寸也会有所不同。

关于java - Android 内存使用情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28747401/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com