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








Syntax

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

public long skip(long n)  throws IOException

Example

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

/*  ww w. ja  v  a 2 s  .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 is = new FileInputStream("C:/test.txt");

    // input stream is converted to buffered input stream
    BufferedInputStream bis = new BufferedInputStream(is);

    // read until a single byte is available
    while (bis.available() > 0) {
      // skip single byte from the stream
      bis.skip(1);

      // read next available byte and convert to char
      char c = (char) bis.read();
      System.out.print(c);
    }
  }
}