mossypne
mossypne

Reputation: 15

Where is my text file saved?

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

Answers (2)

Jonik
Jonik

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

Igor Kostenko
Igor Kostenko

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

Related Questions