save static data in android

In some situations you need to save the data for your android application statically. Which means you need to save the data during the design process of your android application. For example the information for the help topic, licence agreements for the application etc. So in this post i explain how to save data statically in android.



Step 1: Create a new folder named "raw" under the "res" folder. 
android data saving


Step 2 : Create a text file of needed contents with file extension ".txt" and paste it in the "raw" folder.
how to save data in android
Step 3: Create an object of "InputStream" class with the "getResources()" and "openRawResources()" methods.
   Example:
               InputStream im = getResources().openRawResource(R.raw.myfile);


Step 4: Obtain an object of "BufferedReader" class using the object of "InputStream".
  Example:
               BufferedReader br = new BufferedReader(new InputStreamReader(im));


Step 5: Read the data using  the "readLine()" method using "BufferedReader" object.
  Example:
              String data = null;
try {
while((data=br.readLine())!=null)
{
Toast.makeText(getBaseContext(), data, Toast.LENGTH_LONG).show();
}
        } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
        }


Watch Video Tutorial of this Topic