Java LineNumberReader(Reader in, int sz) Constructor

Syntax

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

public LineNumberReader(Reader in,    int sz)

Example

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


//from  w w w  .ja va2s  .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,200);

    // 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();
  }
}