Java FilterInputStream.read(byte[] b)
Syntax
FilterInputStream.read(byte[] b) has the following syntax.
public int read(byte[] b) throws IOException
Example
In the following code shows how to use FilterInputStream.read(byte[] b) method.
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FilterInputStream;
import java.io.InputStream;
/*w ww . j ava 2s. c o m*/
public class Main {
public static void main(String[] args) throws Exception {
byte[] buffer = new byte[6];
// create input streams
InputStream is = new FileInputStream("C://test.txt");
FilterInputStream fis = new BufferedInputStream(is);
// returns number of bytes read to buffer
int i = fis.read(buffer);
// prints
System.out.println("Number of bytes read: " + i);
// for each byte in buffer
for (byte b : buffer) {
// converts byte to character
char c = (char) b;
System.out.println("Character read: " + c);
}
}
}
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »