【问题标题】:Where is my text file saved?我的文本文件保存在哪里?
【发布时间】:2014-01-10 21:32:07
【问题描述】:

我创建了一个文本文件,但似乎无法找到它的保存位置以检查数据是否正确保存!

这是我正在使用的代码:

FileOutputStream fos = new FileOutputStream("userAccounts.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);   
oos.writeObject(Global.getInstance().userArray); 
oos.close(); 

【问题讨论】:

    标签: android file-io android-file


    【解决方案1】:

    我认为这行不通:

    01-10 23:52:56.864    6076-6076/org.example.jonik E/FileTestActivity﹕ 
        java.io.FileNotFoundException: /userAccounts.txt: 
        open failed: EROFS (Read-only file system)
    

    请参阅 this answer 了解为什么不这样做; 您正在尝试写入内部存储的根目录。 该答案还建议了可能是您实际需要的替代方案! (见getFilesDir()getExternalFilesDir()。)

    顺便说一句,这是检查FileOutputStream 尝试写入文件的位置的简单方法(包装在try-catch 中):

    File file = new File("userAccounts.txt");
    Log.i(TAG, "Path: " + file.getCanonicalPath()); // -> "Path: /userAccounts.txt"
    

    【讨论】:

      【解决方案2】:

      此文件位于data/data/your.package.name/files/ 文件夹中。 您可以在模拟器或 root 设备上使用 DDMS 文件资源管理器查看此文件。

      【讨论】:

      • 我的数据文件夹是空的。我的设备也root了
      猜你喜欢
      • 2012-09-01
      • 1970-01-01
      • 2012-05-26
      • 1970-01-01
      • 2012-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-26
      相关资源
      最近更新 更多