Javatpoint Logo
Javatpoint Logo

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

Constructor Description
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

Method Description
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.




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA