Java BufferedOutputStream.flush()
Syntax
BufferedOutputStream.flush() has the following syntax.
public void flush() throws IOException
Example
In the following code shows how to use BufferedOutputStream.flush() method.
/*w ww .j a va2 s .co m*/
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
public class Main {
public static void main(String[] args) throws Exception {
FileInputStream is = new FileInputStream("c:/test.txt");
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(baos);
int value;
while ((value = bis.read()) != -1) {
bos.write(value);
}
bos.flush();
for (byte b : baos.toByteArray()) {
char c = (char) b;
System.out.println(c);
}
}
}
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »