2014-01-10 62 views
0

我創建了一個文本文件,但似乎無法找到它的保存位置,以檢查數據是否保存正確!我的文本文件保存在哪裏?

這是我使用的代碼:

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

回答

0

該文件位於data/data/your.package.name/files/文件夾中。 您可以在模擬器或根設備上使用DDMS File Explorer查看此文件。

+0

我的數據文件夾爲空。我的設備也是紮根的 – mossypne

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"