InputStreamReader




An InputStreamReader is used to read data from a file.

Example:

public boolean readInFromPrivateFile()
{
   try
   {
     // open the file for reading
     InputStream instream = openFileInput("filename.txt");

     // if file is available for reading
     if (instream != null)
     {
       // prepare the file for reading
       InputStreamReader inputreader = new InputStreamReader(instream);
       BufferedReader br = new BufferedReader(inputreader);
      
       String line = "";
      
       // read every line of the file into the line-variable, one line at the time
       while (( line = br.readLine()) != null)
       {
         // the line has been read in
         line = line.trim();
        
         // do whatever with the data
        
       } // end of while (( line = br.readLine()) != null)
      
     } // if (instream != null)
    
     // close the file
     instream.close();
   }
   catch (Exception e)
   {
     return false;
   }
  
   return true;
} // end of readInFromPrivateFile()