import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
publicclass MainClass {
publicstaticvoid main(String[] args) {
String s;
try {
FileReader fr = new FileReader("c:\\myfile.txt");
BufferedReader br = new BufferedReader(fr);
while ((s = br.readLine()) != null)
System.out.println(s);
} catch (IOException e) {
System.out.println("io error");
}
}
}
And given that myfile.txt contains the following two lines of data:
ab
cd