Java BufferedWriter Class

Java BufferedWriter class is used to provide buffering for Writer instances. It makes the performance fast. It inherits Writer class. The buffering characters are used for providing the efficient writing of single arrays, characters, and strings.


Class declaration

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


Class constructors

ConstructorDescription
BufferedWriter(Writer wrt)It is used to create a buffered character output stream that uses the default size for an output buffer.
BufferedWriter(Writer wrt, int size)It is used to create a buffered character output stream that uses the specified size for an output buffer.

Class methods

MethodDescription
void newLine()It is used to add a new line by writing a line separator.
void write(int c)It is used to write a single character.
void write(char[] cbuf, int off, int len)It is used to write a portion of an array of characters.
void write(String s, int off, int len)It is used to write a portion of a string.
void flush()It is used to flushes the input stream.
void close()It is used to closes the input stream

Example of Java BufferedWriter

Let's see the simple example of writing the data to a text file testout.txt using Java BufferedWriter.

Output:

success

testout.txt:

Welcome to javaTpoint.




Latest Courses