BufferedInputStream skip(long) method in Java with Examples
The skip(long) method of BufferedInputStream class in Java is used to skip n bytes of data from the buffered input stream. The number of bytes skipped is stored and returned as long type. The termination condition involves either of the two:
- Either reading into a byte array until n-bytes are covered or,
- When the end of the input, stream is met.
However, if a negative value is passed then no skipping takes place.
public long skip(long n)
Parameters: This method accepts n of long type that represents the number of bytes required to be skipped from the input stream.
Return value: This method returns the number of bytes skipped as long type.
Exception: This method throws IOException if this input stream has been closed by invoking the close() method or the stream is unsupportive of seeking, or any other I/O error occurs.
Below programs illustrates skip(long) method in BufferedInputStream class in IO package:
Program 1: Assume the existence of file “c:/demo.txt”.
Program 2: Assume the existence of file “c:/demo.txt”.
K R K
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.