Java FilterReader.mark(int readAheadLimit)
Syntax
FilterReader.mark(int readAheadLimit) has the following syntax.
public void mark(int readAheadLimit) throws IOException
Example
In the following code shows how to use FilterReader.mark(int readAheadLimit) method.
/*from w ww .j a v a 2 s. co m*/
import java.io.FilterReader;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
public class Main {
public static void main(String[] args) throws Exception {
Reader r = new StringReader("ABCDEF");
// create new filter reader
FilterReader fr = new FilterReader(r) {};
// reads and prints FilterReader
System.out.println((char) fr.read());
System.out.println((char) fr.read());
// mark invoked at this position
fr.mark(0);
System.out.println("mark() invoked");
System.out.println((char) fr.read());
System.out.println((char) fr.read());
// reset() repositioned the stream to the mark
fr.reset();
System.out.println("reset() invoked");
System.out.println((char) fr.read());
System.out.println((char) fr.read());
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »