Java CharArrayReader.mark(int readAheadLimit)

Syntax

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

public void mark(int readAheadLimit)  throws IOException

Example

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


/*  ww w .  ja v  a  2 s  . c o m*/
import java.io.CharArrayReader;

public class Main {
  public static void main(String[] args) throws Exception {

    char[] ch = { 'A', 'B', 'C', 'D', 'E' };


    CharArrayReader car = new CharArrayReader(ch);

    // read and print the characters from the stream
    System.out.println(car.read());
    System.out.println(car.read());

    // mark() is invoked at this position
    car.mark(0);
    System.out.println("Mark() is invoked");
    System.out.println(car.read());
    System.out.println(car.read());

    // reset() is invoked at this position
    car.reset();
    System.out.println("Reset() is invoked");
    System.out.println(car.read());
    System.out.println(car.read());
    System.out.println(car.read());

  }
}

The code above generates the following result.