Left Index

Internal Storage

Android Internal Storage is the storage of the private data on the device memory. By default, saving and loading files to the internal storage are private to the application and other applications will not have access to these files. When the user uninstalls the applications the internal stored files associated with the application are also removed.

We will discuss here read and write file using openFileInput() and openFileOutput() from the Java I/O classes to modify reading and writing streams from and to local files.

  • openFileOutput(): returns an instance of FileOutputStream. After that we can call write method to write data on the file. Its syntax is given below:
  • openFileInput(): returns an instance of FileInputStream.

Below code snippet show you access FileOuputStream object and write data into file:

try {
    FileOutputStream fos = openFileOutput("sample", MODE_PRIVATE);
    fos.write("This is example of Android Internal Storage".getBytes());
} catch (IOException e) {
    Toast.makeText(this, "File writing error: " + e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();

Below code snippet show you access FileInputStream object and read file data:

try {
    FileInputStream fis = openFileInput("sample");

    int ch;
    StringBuffer strBuff = new StringBuffer();
    while ((ch = fis.read()) != -1) {


    // display saved file data 
    Toast.makeText(this, "File data: " + strBuff.toString(), Toast.LENGTH_SHORT).show();
} catch (IOException e) {
    Toast.makeText(this, "File reading error: " + e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();

All internal file will save /data/data/{your application package name} as shown in screen shot below: