Using Internal Storage
suggest changeBy default, any files that you save to Internal Storage are private to your application. They cannot be accessed by other applications, nor the user under normal circumstances. These files are deleted when the user uninstalls the application.
To Write Text to a File
String fileName= "helloworld";
String textToWrite = "Hello, World!";
FileOutputStream fileOutputStream;
try {
fileOutputStream = openFileOutput(fileName, Context.MODE_PRIVATE);
fileOutputStream.write(textToWrite.getBytes());
fileOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
If write throws, close is skipped.
To Append Text to an Existing File
Use Context.MODE_APPEND for the mode parameter of openFileOutput. openFileOutput is a Context method, so this sample is called on an activity or another Context.
fileOutputStream = openFileOutput(fileName, Context.MODE_APPEND);
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents