user1135357 user1135357 - 1 year ago 80
Android Question

Where do files get saved in Android?

I am developing an application which writes some JSON data in a text file:

FileOutputStream fOut;
fOut = openFileOutput("myfile.txt", MODE_PRIVATE);
OutputStreamWriter osw = new OutputStreamWriter(fOut);

I am testing this application on the device and when I plug it in my computer, I am not able to see the file. Can you please tell me under which directory is it stored and do I need to set the operating mode of the file to
in order to see it please?

Answer Source

Plugging it into your computer is mounting it to the SD card, usually. To save to that, get the SD card root directory File with Environment.getExternalStorageDirectory() and then construct a new File with that File and your desired string filename as the arguments. That will save it to your SD card which should be the first folder you see when you mount it on your computer.

By the way, for writing text/JSON straight to a file, just use FileWriter.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download