2

I have recently begun a project which involves me saving a string of results from my android application to the internal storage of my phone. This is the code that I have used to do this:

case R.id.saveButton:
            String fileName = "testFile";
            FileOutputStream outputStream;
            try{
                outputStream = openFileOutput(fileName, Context.MODE_PRIVATE);
                outputStream.write(results.getBytes());
                outputStream.close();
                Toast.makeText(getApplicationContext(), "File Saved", Toast.LENGTH_LONG).show();
            }catch(IOException e){
                Log.d("FILE", "Error when saving the file");
            }

            break;

the toast message is appearing correctly on the screen but I cannot seem to find the file on the phone. My question is where is the file saved on the phone and can I access it? If i cant access it is there a way to make the file visible on the phone so I can access it?

Mark
  • 19
  • 1
  • 3

1 Answers1

1

where is the file saved on the phone

For the default user, for typical devices, it is in /data/data/your.application.id.goes.here/files/. However, you cannot access that directory directly on production hardware. You can:

If i cant access it is there a way to make the file visible on the phone so I can access it?

Not where you are writing it.

Community
  • 1
  • 1
CommonsWare
  • 910,778
  • 176
  • 2,215
  • 2,253
  • @CommonWare Is there a way to save the file to a place I can access it on the emulator? – Mark Mar 15 '17 at 18:01
  • @Mark: See the second and third bullets in my answer. You can access the Android Device Monitor in Android Studio through Tools > Android > Android Device Monitor. I have had some problems with the Monitor in recent months, and so its File Explorer tool may have problems, but it is worth trying. Typically, programmers do not try to get to files on internal storage like this. Instead, they write test cases to see if the files are being written correctly. I cannot remember the last time I pulled a file off of internal storage -- probably at least a couple of years ago. – CommonsWare Mar 15 '17 at 18:13