1package net.codejava.io;
2
3import java.io.BufferedReader;
4import java.io.FileReader;
5import java.io.IOException;
6
7/**
8 * This program demonstrates how to read characters from a text file
9 * using a BufferedReader for efficiency.
10 * @author www.codejava.net
11 *
12 */
13public class TextFileReadingExample3 {
14
15 public static void main(String[] args) {
16 try {
17 FileReader reader = new FileReader("MyFile.txt");
18 BufferedReader bufferedReader = new BufferedReader(reader);
19
20 String line;
21
22 while ((line = bufferedReader.readLine()) != null) {
23 System.out.println(line);
24 }
25 reader.close();
26
27 } catch (IOException e) {
28 e.printStackTrace();
29 }
30 }
31
32}
33