Android 用于缓存的 openFileInput()?
Android openFileInput() for cache?
如果我对Android Storage Options的理解是正确的,至少Internal和External Storage有2个目录:
Internal Storage Files = getFilesDir()
Internal Storage Cache = getCacheDir()
External Storage Files = getExternalFilesDir()
External Storage Cache = getExternalCacheDir()
FileInputStream
和 FileOutputStream
两个外部存储目录都可以使用构造函数创建。例如:
File file = new File(getExternalFilesDir().getAbsolutePath() + File.separator + fileName);
FileInputStream inputStream = new FileInputStream(file);
但是,在内部存储中,您只能使用 openFileInput()
和 openFileOutput()
来创建 FileInputStream
或 FileOutputStream
。例如:
File file = new File(getExternalFilesDir().getAbsolutePath() + File.separator + fileName);
FileInputStream inputStream = openFileInput(file, Context.MODE_PRIVATE);
并且由于 openFileInput()
和 openFileOutput()
从内部存储文件 getFilesDir()
创建了 FileInputStream
和 FileOutputStream
,我假定 FileInputStream
的构造函数和 FileOutputStream
是唯一可用于内部存储缓存 getCacheDir()
的方法。有知识的人可以验证以上信息是否正确吗?
In Internal Storage, however, you may only use openFileInput() and openFileOutput() to create FileInputStream or FileOutputStream.
不,您可以使用 getFilesDir()
和 getCacheDir()
在 internal storage 上创建位置,例如 new File(getCacheDir(), fileName)
.
I assume the constructor of FileInputStream and FileOutputStream are the only method that can be used for Internal Storage Cache getCacheDir().
没有 openFileInput()
直接对应 getCacheDir()
,如果那是你的意思。
如果我对Android Storage Options的理解是正确的,至少Internal和External Storage有2个目录:
Internal Storage Files = getFilesDir()
Internal Storage Cache = getCacheDir()
External Storage Files = getExternalFilesDir()
External Storage Cache = getExternalCacheDir()
FileInputStream
和 FileOutputStream
两个外部存储目录都可以使用构造函数创建。例如:
File file = new File(getExternalFilesDir().getAbsolutePath() + File.separator + fileName);
FileInputStream inputStream = new FileInputStream(file);
但是,在内部存储中,您只能使用 openFileInput()
和 openFileOutput()
来创建 FileInputStream
或 FileOutputStream
。例如:
File file = new File(getExternalFilesDir().getAbsolutePath() + File.separator + fileName);
FileInputStream inputStream = openFileInput(file, Context.MODE_PRIVATE);
并且由于 openFileInput()
和 openFileOutput()
从内部存储文件 getFilesDir()
创建了 FileInputStream
和 FileOutputStream
,我假定 FileInputStream
的构造函数和 FileOutputStream
是唯一可用于内部存储缓存 getCacheDir()
的方法。有知识的人可以验证以上信息是否正确吗?
In Internal Storage, however, you may only use openFileInput() and openFileOutput() to create FileInputStream or FileOutputStream.
不,您可以使用 getFilesDir()
和 getCacheDir()
在 internal storage 上创建位置,例如 new File(getCacheDir(), fileName)
.
I assume the constructor of FileInputStream and FileOutputStream are the only method that can be used for Internal Storage Cache getCacheDir().
没有 openFileInput()
直接对应 getCacheDir()
,如果那是你的意思。