SuperMario32 SuperMario32 - 1 year ago 123
Android Question

Reading and writing to files in internal storage on Android

I'm learning to write and read files from the internal storage on Android. I have this code:

String fileName = "MyFile";
String content = "hello world";

FileOutputStream outputStream = null;
try {
outputStream = openFileOutput(fileName, Context.MODE_PRIVATE);
} catch (Exception e) {

Where is my file stored and how to read it?

Answer Source

The File should be saved under /data/data/Android/urpackagename/ folder.

To read

 FileInputStream in = openFileInput("filename.txt");
InputStreamReader inputStreamReader = new InputStreamReader(in);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
StringBuilder sb = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {

For More Detail with same piece of code Write and Read openFile...() api

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