Java IO Tutorial - Java BufferedReader.readLine()








Syntax

BufferedReader.readLine() has the following syntax.

public String readLine()  throws IOException

Example

In the following code shows how to use BufferedReader.readLine() method.

// w  w w. j a v  a2  s  .  c  om
import java.io.BufferedReader;
import java.io.FileReader;

public class Main {
  public static void main(String[] args) throws Exception {

    String thisLine = null;


    BufferedReader br = new BufferedReader(new FileReader("c:/test.txt"));
    while ((thisLine = br.readLine()) != null) {
      System.out.println(thisLine);
    }

  }
}