【发布时间】:2014-10-03 00:31:27
【问题描述】:
Context IO API(openFileInput 和 openFileOutput)与在 Context.getFilesDir 上使用 Java 的 IO API 有什么区别?
【问题讨论】:
-
当你用谷歌搜索时发生了什么? :)
Context IO API(openFileInput 和 openFileOutput)与在 Context.getFilesDir 上使用 Java 的 IO API 有什么区别?
【问题讨论】:
没什么。比如这里是openFileInput()from ContextImpl的实现(Context的基础实现):
@Override
public FileInputStream openFileInput(String name)
throws FileNotFoundException {
File f = makeFilename(getFilesDir(), name);
return new FileInputStream(f);
}
如果文件名中有目录分隔符,makeFilename() 会在哪里对你大喊大叫。
我个人使用getFilesDir(),因为它更灵活。
【讨论】: