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