Java PushbackInputStream .available ()
Syntax
PushbackInputStream.available() has the following syntax.
public int available() throws IOException
Example
In the following code shows how to use PushbackInputStream.available() method.
import java.io.*;
// ww w.java2s .c o m
public class Main {
public static void main(String[] args) {
byte[] arrByte = new byte[1024];
byte[] byteArray = new byte[]{'j', 'a', 'v', 'a', '2','s','.','c','o','m'};
try {
InputStream is = new ByteArrayInputStream(byteArray);
PushbackInputStream pis = new PushbackInputStream(is);
System.out.println(pis.available());
for (int i = 0; i < byteArray.length; i++) {
arrByte[i] = (byte) pis.read();
System.out.println((char) arrByte[i]);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »