使用 Android 内部存储的文件大小
Size of file using Android Internal Storage
我正在使用:
FileOutputStream fos = getContext().openFileOutput(FILENAME, Context.MODE_APPEND);
将数据字符串存储到文件 FILENAME 中。我想确保当 FILENAME 中的字符串达到 120kB 时我将停止附加任何字符串。如何查询总计 space 被占用?
我试过:
File file = new File(getContext().getFilesDir() + "/" + FILENAME);
Log.i(TAG, "Storage Used (Bytes): " + Long.toString(file.getTotalSpace()));
但它 returns 我的数量很大。可能是因为我引用目录的方式不对?
改为使用方法 length()。来自文档
Returns the size of the partition named by this abstract pathname.
Returns the length of the file denoted by this abstract pathname. The return value is unspecified if this pathname denotes a directory.
所以 getTotalSpace 用于检查有关文件夹或驱动器的信息。
我正在使用:
FileOutputStream fos = getContext().openFileOutput(FILENAME, Context.MODE_APPEND);
将数据字符串存储到文件 FILENAME 中。我想确保当 FILENAME 中的字符串达到 120kB 时我将停止附加任何字符串。如何查询总计 space 被占用?
我试过:
File file = new File(getContext().getFilesDir() + "/" + FILENAME);
Log.i(TAG, "Storage Used (Bytes): " + Long.toString(file.getTotalSpace()));
但它 returns 我的数量很大。可能是因为我引用目录的方式不对?
改为使用方法 length()。来自文档
Returns the size of the partition named by this abstract pathname.
Returns the length of the file denoted by this abstract pathname. The return value is unspecified if this pathname denotes a directory.
所以 getTotalSpace 用于检查有关文件夹或驱动器的信息。