SuperMario32 SuperMario32 - 4 months ago 51
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?


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