Java InputStream.mark(int readlimit)
Syntax
InputStream.mark(int readlimit) has the following syntax.
public void mark(int readlimit)
Example
In the following code shows how to use InputStream.mark(int readlimit) method.
// ww w . j ava 2 s . c o m
import java.io.FileInputStream;
import java.io.InputStream;
public class Main {
public static void main(String[] args) throws Exception {
InputStream is = new FileInputStream("C://test.txt");
// read and print characters one by one
System.out.println("Char : " + (char) is.read());
System.out.println("Char : " + (char) is.read());
System.out.println("Char : " + (char) is.read());
// mark is set on the input stream
is.mark(0);
System.out.println("Char : " + (char) is.read());
System.out.println("Char : " + (char) is.read());
if (is.markSupported()) {
// reset invoked if mark() is supported
is.reset();
System.out.println("Char : " + (char) is.read());
System.out.println("Char : " + (char) is.read());
}
is.close();
}
}
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »