Java ByteArrayInputStream .available ()
Syntax
ByteArrayInputStream.available() has the following syntax.
public int available()
Example
In the following code shows how to use ByteArrayInputStream.available() method.
/* ww w . jav a 2 s. c o m*/
import java.io.ByteArrayInputStream;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
byte[] buf = { 65, 66, 67, 68, 69 };
ByteArrayInputStream bais = new ByteArrayInputStream(buf);
int count = 0;
while ((count = bais.available()) > 0) {
char c = (char) bais.read();
System.out.print("available byte(s) : " + count);
System.out.println(c);
}
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »