The BufferedWriter class possesses the functionality of writing buffers of characters into a file. It extends Writer, which is an abstract class for writing to character streams . While using BufferedWriter, buffering can speed up IO quite a bit. Rather than write single character at a time to the source, the BufferedWriter writes a large amount of data at a time. So, it is typically much faster , especially for disk access and larger data amounts.
When you want to write strings there are two options. The BufferedWriter and the File Writer .
- If you want to write one string the File Writer is better.
- If you want to write multiple strings, the BufferedWriter is more efficient.
While using BufferedWriter, the multiple strings can all be buffered together and as the default buffer size is 8192 characters this become just 1 system call to write. So the BufferedWriter needs to be cleared when called in the event there was something in the buffer.
The following Java program writes an array into the external file using BufferedWriter.