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:
write(int c)
: This method writes a single character to the output stream.write(String str)
: This method writes a string of characters to the output stream.write(String str, int off, int len)
: This method writes a portion of a string of characters to the output stream, starting at the specifiedoff
offset and writinglen
characters.write(char[] cbuf)
: This method writes an array of characters to the output stream.write(char[] cbuf, int off, int len)
: This method writes a portion of an array of characters to the output stream, starting at the specifiedoff
offset and writinglen
characters.newLine()
: This method writes a platform-specific newline character(s) to the output stream.flush()
: This method flushes the output stream, writing any buffered data to the underlying stream.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.