Java BufferedInputStream .read (byte[] b, int off, int len)
Syntax
BufferedInputStream.read(byte[] b, int off, int len) has the following syntax.
public int read(byte[] b, int off, int len) throws IOException
Example
In the following code shows how to use BufferedInputStream.read(byte[] b, int off, int len) method.
//from w ww. j a va2s.c om
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
public class Main {
public static void main(String[] args) throws Exception {
InputStream inStream = new FileInputStream("c:/test.txt");
BufferedInputStream bis = new BufferedInputStream(inStream);
// read number of bytes available
int numByte = bis.available();
// byte array declared
byte[] buf = new byte[numByte];
// read byte into buf , starts at offset 2, 3 bytes to read
bis.read(buf, 2, 3);
// for each byte in buf
for (byte b : buf) {
System.out.println((char) b + ": " + b);
}
}
}
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »