Source of TextFileInputDemo.java


  1: 
  2: import java.io.*;
  3: 
  4: public class TextFileInputDemo
  5: {
  6:     public static void main(String[] args)
  7:     {
  8:        try
  9:        {
 10:            BufferedReader inputStream = 
 11:                new BufferedReader(new FileReader("data.txt")); 
 12:                
 13:            String line = null;
 14:            line = inputStream.readLine( );
 15:            System.out.println("The first line in data.txt is:"); 
 16:            
 17:            System.out.println(line);
 18:            line = inputStream.readLine( );
 19:            System.out.println("The second line in data.txt is:");
 20:            System.out.println(line); 
 21:            inputStream.close( );
 22:        }
 23:        catch(FileNotFoundException e)
 24:        {
 25:            System.out.println("File data.txt was not found");
 26:            System.out.println("or could not be opened.");
 27:        }
 28:        catch(IOException e)
 29:        {
 30:            System.out.println("Error reading from file data.txt.");
 31:        }
 32:     }
 33: }