Java Reference
In-Depth Information
Display 10.7
Reading Input from a Text File Using BufferedReader (part 2 of 2)
9 try
10 {
11 BufferedReader inputStream =
12
new BufferedReader( new FileReader("morestuff2.txt"));
13 String line = inputStream.readLine();
14 System.out.println(
15 "The first line read from the file is:");
16 System.out.println(line);
17
18 line = inputStream.readLine();
19 System.out.println(
20 "The second line read from the file is:");
21 System.out.println(line);
22 inputStream.close();
23 }
24 catch (FileNotFoundException e)
25 {
26 System.out.println("File morestuff2.txt was not found");
27 System.out.println("or could not be opened.");
28 }
29 catch (IOException e)
30 {
31 System.out.println("Error reading from morestuff2.txt.");
32 }
33 }
34 }
F ILE morestuff2.txt
1 2 3
Jack jump over
the candle stick.
This file could have been made with a
text editor or by another Java program.
Screen Output
The first line read from the file is:
1 2 3
The second line read from the file is:
Jack jump over
Search WWH ::




Custom Search