Java IO Tutorial - Java LineNumberInputStream .mark (int readlimit)








Syntax

LineNumberInputStream.mark(int readlimit) has the following syntax.

public void mark(int readlimit)

Example

In the following code shows how to use LineNumberInputStream.mark(int readlimit) method.

/*  w w  w  .j  a  va 2s . c  o  m*/

import java.io.FileInputStream;
import java.io.IOException;
import java.io.LineNumberInputStream;

public class Main {
  public static void main(String[] args) throws IOException {
    FileInputStream fis = new FileInputStream("C:/test.txt");
    LineNumberInputStream lnis = new LineNumberInputStream(fis);

    System.out.println((char) lnis.read());
    System.out.println((char) lnis.read());

    lnis.mark(0);
    System.out.println("mark() invoked");
    System.out.println((char) lnis.read());
    System.out.println((char) lnis.read());

    if (lnis.markSupported()) {
      lnis.reset();
      System.out.println("reset() invoked");
      System.out.println((char) lnis.read());
      System.out.println((char) lnis.read());
    }

  }
}