ByteArrayInputStream skip Example
ByteArrayInputStream class skip example. This example shows you how to use skip method.
ByteArrayInputStream class skip example. public long skip(long n) Skips n bytes of input from this input stream. Fewer bytes might be skipped if the end of the input stream is reached.
Here is the code
/**
* @ # Skip.java
* A class repersenting use to skip method
* of ByteArrayInputStream class in java.io package
* version 03 June 2008
* author Rose India
*/
import java.io.*;
public class Skip {
public static void main(String args[]) throws Exception {
byte b[] = {1, 2, 3, 4, 5};
ByteArrayInputStream baStream = new ByteArrayInputStream(b);
System.out.println("Byte of data from input stream.");
//Returns the number of remaining bytes
while (baStream.available() != 0) {
//Read ByteArrayInputStream
System.out.println(baStream.read());
baStream.skip(1);
}
//Closing ByteArrayInputStream
baStream.close();
}
} |
Output
Byte of data from input stream.
1
3
5 |
|