Java FilterOutputStream .write (byte[] b)
Syntax
FilterOutputStream.write(byte[] b) has the following syntax.
public void write(byte[] b) throws IOException
Example
In the following code shows how to use FilterOutputStream.write(byte[] b) method.
//www . j a va 2 s . co m
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FilterOutputStream;
import java.io.OutputStream;
public class Main {
public static void main(String[] args) throws Exception {
byte[] buffer = { 65, 66, 67, 68, 69 };
int i = 0;
OutputStream os = new FileOutputStream("C://test.txt");
FilterOutputStream fos = new FilterOutputStream(os);
// writes buffer to the output stream
fos.write(buffer);
// forces byte contents to written out to the stream
fos.flush();
// create input streams
FileInputStream fis = new FileInputStream("C://test.txt");
while ((i = fis.read()) != -1) {
// converts integer to the character
char c = (char) i;
System.out.println("Character read: " + c);
}
fos.close();
fis.close();
}
}
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »