Reputation: 15
I've created a text file but can't seem to find where it is saved to check whether the data was saved correctly!
This is the code i'm using:
FileOutputStream fos = new FileOutputStream("userAccounts.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(Global.getInstance().userArray);
oos.close();
Upvotes: 0
Views: 3132
Reputation: 81751
I don't think that will work:
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)
See this answer for why not; you're trying to write to the root of internal storage.
That answer also suggests alternatives which likely are what you actually need! (See getFilesDir()
and getExternalFilesDir()
.)
By the way, this is an easy way to check where your FileOutputStream
is trying write the file (wrap in try-catch):
File file = new File("userAccounts.txt");
Log.i(TAG, "Path: " + file.getCanonicalPath()); // -> "Path: /userAccounts.txt"
Upvotes: 1
Reputation: 2874
This file is located in data/data/your.package.name/files/
folder.
You can see this file with DDMS File Explorer on emulator or rooted device.
Upvotes: 0