0

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(); 
Jonik
  • 80,077
  • 70
  • 264
  • 372
mossypne
  • 15
  • 1
  • 2
  • 6

2 Answers2

1

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"
Community
  • 1
  • 1
Jonik
  • 80,077
  • 70
  • 264
  • 372
0

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.

Igor Kostenko
  • 2,754
  • 7
  • 30
  • 57