Android Storing Files in Internal & External Storage Using Internal Storage

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

By 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();
}

To Append Text to an Existing File

Use Context.MODE_APPEND for the mode parameter of openFileOutput

fileOutputStream = openFileOutput(fileName, Context.MODE_APPEND);


Got any Android Question?