Java BufferedOutputStream Class

Java BufferedOutputStream class is used for buffering an output stream. It internally uses buffer to store data. It adds more efficiency than to write data directly into a stream. So, it makes the performance fast.

For adding the buffer in an OutputStream, use the BufferedOutputStream class. Let's see the syntax for adding the buffer in an OutputStream:


Java BufferedOutputStream class declaration

Let's see the declaration for Java.io.BufferedOutputStream class:


Java BufferedOutputStream class constructors

ConstructorDescription
BufferedOutputStream(OutputStream os)It creates the new buffered output stream which is used for writing the data to the specified output stream.
BufferedOutputStream(OutputStream os, int size)It creates the new buffered output stream which is used for writing the data to the specified output stream with a specified buffer size.

Java BufferedOutputStream class methods

MethodDescription
void write(int b)It writes the specified byte to the buffered output stream.
void write(byte[] b, int off, int len)It write the bytes from the specified byte-input stream into a specified byte array, starting with the given offset
void flush()It flushes the buffered output stream.

Example of BufferedOutputStream class:

In this example, we are writing the textual information in the BufferedOutputStream object which is connected to the FileOutputStream object. The flush() flushes the data of one stream and send it into another. It is required if you have connected the one stream with another.

Output:

Success

testout.txt

Welcome to javaTpoint.




Latest Courses