Randomly Named User
Randomly Named User

Reputation: 1949

Where are files created using FileOutputStream on Android?

I've created a file in my code, as shown below

 FileOutputStream fOut = openFileOutput("samplefile.txt", MODE_WORLD_READABLE);
 OutputStreamWriter osw = new OutputStreamWriter(fOut); 
 osw.write(text);
 osw.flush();
 osw.close();

Now, I know that the file is getting created because I can read the file when I do this:

     FileInputStream fIn = openFileInput("samplefile.txt");
     InputStreamReader isr = new InputStreamReader(fIn);
     char[] inputBuffer = new char[text.length()];
     isr.read(inputBuffer);
     String readString = new String(inputBuffer);
     System.out.println(readString);

So the text is getting read back. However, I can't find the file on my device. Where does it go?

Thanks in advance.

Upvotes: 2

Views: 1090

Answers (3)

Luis
Luis

Reputation: 3571

The file is being saved to internal storage (see this link).

You can retrieve the path of the file with getFilesDir() (see this link).

The path is /data/data/yourapplicationpackagename/files.

Upvotes: 2

Mahdi-bagvand
Mahdi-bagvand

Reputation: 1407

You can get the address of it be below line Code

 File file = getFileStreamPath("samplefile.txt");

And for print it

String s  = file.getAbsolutePath();

Upvotes: 3

Scary Wombat
Scary Wombat

Reputation: 44813

If you googled you could find this site link

which mentions

Android allows to persists application data via the file system. For each application the Android system creates a data/data/[application package] directory.

Upvotes: 1

Related Questions