Java BufferedInputStream skip() Example
BufferedInputStream class skip() method example. This example shows you how to use skip() method.
Syntax is : public long skip(long n) throws IOException
This method skips specified number of elements in the buffer and returns the actual number of bytes skipped.
Here is the code.
/**
* @(#) SkipBufferedInputStream.java
* A class representing use of method skip() of BufferedInputStream class in
java.io Package.
* @Version 03-May-2008
* @author Rose India Team
*/
import java.io.*;
public class SkipBufferedInputStream {
public static void main(String[] args) throws IOException{
/* Construct an buffer input stream using some String value.
This is deprecated method in java api 1.6. */
StringBufferInputStream obj = new StringBufferInputStream("MAHENDRA");
// Construct the buffer using the buffer input stream obj.
BufferedInputStream bin = new BufferedInputStream(obj);
// read() method call.
System.out.println("First element is : "+(char)bin.read());
System.out.println("Next element is : "+(char)bin.read());
System.out.println("Next element is : "+(char)bin.read());
// skip() skips specified number of elements.
bin.skip(2);
System.out.println("In this example skip() method skips 2 elements.");
System.out.println("Next element is : "+(char)bin.read());
System.out.println("Next element is : "+(char)bin.read());
System.out.println("Next element is : "+(char)bin.read());
}
} |
Output of the program.
First element is : M
Next element is : A
Next element is : H
In this example skip() method skips 2 elements.
Next element is : D
Next element is : R
Next element is : A |
|