【问题标题】:Difference between Context.openFileInput() and using the Java.IO classesContext.openFileInput() 和使用 Java.IO 类之间的区别
【发布时间】:2014-10-03 00:31:27
【问题描述】:

Context IO API(openFileInput 和 openFileOutput)与在 Context.getFilesDir 上使用 Java 的 IO API 有什么区别?

【问题讨论】:

  • 当你用谷歌搜索时发生了什么? :)

标签: java android api io


【解决方案1】:

没什么。比如这里是openFileInput()from ContextImpl的实现(Context的基础实现):

@Override
public FileInputStream openFileInput(String name)
  throws FileNotFoundException {
  File f = makeFilename(getFilesDir(), name);
  return new FileInputStream(f);
}

如果文件名中有目录分隔符,makeFilename() 会在哪里对你大喊大叫。

我个人使用getFilesDir(),因为它更灵活。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-30
    • 2014-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-02
    • 2011-04-07
    相关资源
    最近更新 更多