Java IO Tutorial - Java FilterInputStream.skip(long n)








Syntax

FilterInputStream.skip(long n) has the following syntax.

public long skip(long n)  throws IOException

Example

In the following code shows how to use FilterInputStream.skip(long n) method.

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FilterInputStream;
import java.io.InputStream;
/*w w  w .  j ava2  s.  c om*/
public class Main {
  public static void main(String[] args) throws Exception {

    int i = 0;

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

    while ((i = fis.read()) != -1) {
      // converts integer to character
      char c = (char) i;

      // skips 3 bytes
      fis.skip(3);

      System.out.println("Character read: " + c);
    }

  }
}