Introduction
Store private data on the device memory. You can directly save your application data to the internal memory. By default, data is saved in internal memory and other applications cannot access it. When you uninstall your application all files will be removed from the device.
The FileInoutStream and FileOutPutStream classes are used to read and write the data of the files.
FileInputStream
FileInputStream gets input bytes from a file. The FileInputStream class provides the facility to read streams of raw bytes such as image data. It extends the InputStream class. The following are methods provided by the fileInputStream class:
FileOutputStraem is an output stream for writing data to a file. It extends the OutputStream class. Methods provided by the outputStream class are:
Create a project like this:
Step 2
Create an XML file and write the following:
Step 3
- public int read(): this method reads a single byte from this Stream and returns this as an integer in the range from 0 to 225
- public void close(): this method closes the stream.
-
public void close(): This method is used to close the stream
- public void write(): This method is used to write a single byte to the stream

- <!-- In this you will take a Relative Layout that display the elements in relative position -->
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".MainActivity" >
- <!-- Take an EditText that contains the file name and this file name will be got by calling getString() -->
- <EditText
- android:id="@+id/editText1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentRight="true"
- android:layout_alignParentTop="true"
- android:layout_marginRight="20dp"
- android:layout_marginTop="24dp"
- android:ems="10" >
- <requestFocus />
- </EditText>
- <!-- Take an EditText that contains the date and this date will be got by calling getString() -->
- <EditText
- android:id="@+id/editText2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignRight="@+id/editText1"
- android:layout_below="@+id/editText1"
- android:layout_marginTop="24dp"
- android:ems="10" />
- <!-- This Textiew is used to diplay the text (filename -->
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignBaseline="@+id/editText1"
- android:layout_alignBottom="@+id/editText1"
- android:layout_alignParentLeft="true"
- android:text="File Name:" />
- <!-- This Textiew is used to diplay the text(date) -->
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignBaseline="@+id/editText2"
- android:layout_alignBottom="@+id/editText2"
- android:layout_alignParentLeft="true"
- android:text="Data:" />
- <!-- This button is used to perform click event that saves the file to the internal storage -->
- <Button
- android:id="@+id/buttonSave"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="70dp"
- android:layout_marginTop="150dp"
- android:text="save" />
- <!-- This button is used to perform click event that read the file from the internal storage -->
- <Button
- android:id="@+id/buttonRead"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="140dp"
- android:layout_marginTop="150dp"
- android:text="read" />
- </RelativeLayout>



Join the conversation! Your thoughts help the community grow.