Java Methods of BufferedWriter

The BufferedWriter class provides several methods that can be used to write data to an output stream. Here are some of the most commonly used methods:

  1. write(int c): This method writes a single character to the output stream.

  2. write(String str): This method writes a string of characters to the output stream.

  3. write(String str, int off, int len): This method writes a portion of a string of characters to the output stream, starting at the specified off offset and writing len characters.

  4. write(char[] cbuf): This method writes an array of characters to the output stream.

  5. write(char[] cbuf, int off, int len): This method writes a portion of an array of characters to the output stream, starting at the specified off offset and writing len characters.

  6. newLine(): This method writes a platform-specific newline character(s) to the output stream.

  7. flush(): This method flushes the output stream, writing any buffered data to the underlying stream.

  8. close(): This method closes the output stream and releases any system resources associated with it.

In addition to these methods, the BufferedWriter class also has a append() method that can be used to write data to the output stream. The append() method is overloaded and can take a char, a CharSequence, or a CharSequence with an offset and length.

Note that many of these methods can throw an IOException if there is an error while writing to the stream. Therefore, it is important to handle exceptions appropriately when using these methods.