Java Reader.mark(int readAheadLimit)
Syntax
Reader.mark(int readAheadLimit) has the following syntax.
public void mark(int readAheadLimit) throws IOException
Example
In the following code shows how to use Reader.mark(int readAheadLimit) method.
//from w w w. j av a 2s .c o m
import java.io.*;
public class Main {
public static void main(String[] args) {
try {
String s = "tutorial from java2s.com";
Reader reader = new StringReader(s);
for (int i = 0; i < 5; i++) {
char c = (char) reader.read();
System.out.println(c);
}
reader.mark(10);
for (int i = 0; i < 6; i++) {
char c = (char) reader.read();
System.out.println(c);
}
reader.reset();
for (int i = 0; i < 6; i++) {
char c = (char) reader.read();
System.out.println(c);
}
reader.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »