BufferedOutputStream extends FilterOutputStream.
BufferedOutputStream implements a buffered output stream. By setting up such an output stream, an application can write bytes to the underlying output stream without necessarily causing a call to the underlying system for each byte written.
Constructors
Methods
package com.java.io;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class BufferedOutputStreamExample {
public static void main(String[] args) {
FileOutputStream fos = null;
BufferedOutputStream bos = null;
String data = "Testing data";
try {
fos = new FileOutputStream("/Test/TestFolder/test-file3.txt");
bos = new BufferedOutputStream(fos);
byte[] bytesArray = data.getBytes();
bos.write(bytesArray);
bos.flush();
System.out.println("Data written to File");
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
// Closing the streams
if (fos != null)
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
if (bos != null)
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Data written to File
File
Related Article