Java LineNumberReader(Reader in) Constructor

Syntax

LineNumberReader(Reader in) constructor from LineNumberReader has the following syntax.

public LineNumberReader(Reader in)

Example

In the following code shows how to use LineNumberReader.LineNumberReader(Reader in) constructor.


// w  w w  . java2  s .co  m
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;

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);

    // read till the end of the stream
    while ((i = lnr.read()) != -1) {
      // skip one byte
      lnr.skip(1);

      // converts integer to char
      char c = (char) i;

      // prints char
      System.out.print(c);
    }
    lnr.close();
  }
}