写入文件存储

时间:2020-03-14 05:32:21

标签: android file kotlin storage android-external-storage

我想将文件写入外部存储,而当我看着usableSpace的{​​{1}}时,它说只有515.74MB。

这是目录的典型context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)大小吗?如果您需要更多的存储空间来写入数据,该怎么办?

usableSpace

更新

在模拟器上进行测试时,不同存储目录的usableSpace如下

private fun getStorageDirectory(): File {
    return if (isExternalStorageWritable()) {
        context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
    } else {
        context.filesDir
    }
}


private fun getUsableSpace(): Long {
    return getStorageDirectory()?.usableSpace ?: 0L
}

在Google Pixel XL上进行测试时,不同存储目录的usableSpace如下

DEBUG ~~ [context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).usableSpace 515739648] 515.74MB
DEBUG ~~ [context.getExternalFilesDir(null).usableSpace 515739648] 515.74MB
DEBUG ~~ [context.filesDir.usableSpace 515739648] 515.74MB
DEBUG ~~ [context.externalCacheDir.usableSpace 515735552] 515.74MB
DEBUG ~~ [context.cacheDir.usableSpace 515735552] 515.74MB

所以我想在真正的设备上您有更多的写空间。

0 个答案:

没有答案