Read a text file line by line with BufferReader in Java
Description
The following code shows how to read a text file line by line with BufferReader.
Example
/* www.j av a 2 s. c o m*/
import java.io.BufferedReader;
import java.io.FileReader;
public class Main {
public static void main(String[] argv) throws Exception {
BufferedReader is = new BufferedReader(new FileReader("a.bat"));
String line;
while ((line = is.readLine()) != null){
System.out.println(line);
}
is.close();
}
}
The code above generates the following result.