Java IO Tutorial - Java BufferedInputStream.mark(int readlimit)








Syntax

BufferedInputStream.mark(int readlimit) has the following syntax.

public void mark(int readlimit)

Example

In the following code shows how to use BufferedInputStream.mark(int readlimit) method.

/*from  w ww .  ja va 2s.  c o  m*/


import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;

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

    // read and print characters one by one
    System.out.println((char) bis.read());
    System.out.println((char) bis.read());
    System.out.println((char) bis.read());

    // mark is set on the input stream
    bis.mark(0);
    System.out.println((char) bis.read());

    // reset is called
    bis.reset();

    // read and print characters
    System.out.println((char) bis.read());
    System.out.println((char) bis.read());

  }
}