Java IO Tutorial - Java FilterInputStream.reset()








Syntax

FilterInputStream.reset() has the following syntax.

public void reset()  throws IOException

Example

In the following code shows how to use FilterInputStream.reset() method.

/*from   ww w  .  j  av  a 2 s .c  om*/
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;

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

    // create input streams
    InputStream is = new FileInputStream("C://test.txt");
    FilterInputStream fis = new BufferedInputStream(is);

    // reads and prints filter input stream
    System.out.println((char) fis.read());
    System.out.println((char) fis.read());

    // mark invoked at this position
    fis.mark(0);
    System.out.println("mark() invoked");
    System.out.println((char) fis.read());
    System.out.println((char) fis.read());

    // reset() repositioned the stream to the mark
    fis.reset();
    System.out.println("reset() invoked");
    System.out.println((char) fis.read());
    System.out.println((char) fis.read());

  }
}