This code snippet shows how to read a file using the BufferedReader class.
import java.io.*;
class FileReader {
public static void main(String args[]){
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader( "filename.here"));
String line = "";
while ((line = reader.readLine()) !=null) {
System.out.println(line);
}
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
try {
if (reader !=null) {
reader.close();
}
} catch (IOException ioEx) {
System.out.println(ioEx.getMessage());
}
}
}
}
No comments:
Post a Comment