BufferedReader.readLine() Example
The program outputs the contents of all files in a particular directory. It reads each of the files line by line. The method readLine() considers a line to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed.
// BufferedReader.readLine Example
import java.io.*;
class ReadLineExample {
static public void main(String[] args) {
try {
File f = new File("MySpace"+File.separator+"Dogs");
File[] fa = f.listFiles();
BufferedReader reader;
for(int i=0;i<fa.length;++i) {
if(fa[i].isFile()) {
System.out.println(fa[i]+":");
reader = new BufferedReader(new FileReader(fa[i]));
String s;
while( (s = reader.readLine()) != null) {
System.out.println(s);
}
}
}
}
catch(Exception e) {
System.err.println("problem with file: "+e.getMessage());
}
}
}
