Java LineNumberReader.read()

Syntax

LineNumberReader.read() has the following syntax.

public int read()  throws IOException

Example

In the following code shows how to use LineNumberReader.read() method.


import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;
/*from www . j a  v a  2  s .  c  om*/
public class Main {
  public static void main(String[] args) throws IOException {

    int i;

    // create new reader
    FileReader fr = new FileReader("C:/test.txt");
    LineNumberReader lnr = new LineNumberReader(fr);

    while ((i = lnr.read()) != -1) {
      // converts int to char
      char c = (char) i;

      // prints character
      System.out.println(c);
    }
        lnr.close();
  }
}