Java BufferedReader.mark(int readAheadLimit)

Syntax

BufferedReader.mark(int readAheadLimit) has the following syntax.

public void mark(int readAheadLimit)  throws IOException

Example

In the following code shows how to use BufferedReader.mark(int readAheadLimit) method.


//from  www .java  2  s  .  co m
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
  public static void main(String[] args) throws Exception {
    InputStream is = new FileInputStream("c:/test.txt");

    InputStreamReader isr = new InputStreamReader(is);

    BufferedReader br = new BufferedReader(isr);

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

    br.mark(26);
    System.out.println("mark() invoked");
    System.out.println((char) br.read());
    System.out.println((char) br.read());

    br.reset();
    System.out.println("reset() invoked");
    System.out.println((char) br.read());
    System.out.println((char) br.read());

  }
}