Java Methods of FileWriter
Java FileWriter
inherits several methods from its superclass, OutputStreamWriter
, as well as some methods of its own. Here are some of the methods available in the FileWriter
class:
write(int c)
: This method writes a single character to the output stream.write(char[] cbuf)
: This method writes an array of characters to the output stream.write(String str)
: This method writes a string 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 writing up tolen
characters.write(String str, int off, int len)
: This method writes a portion of a string to the output stream, starting at the specifiedoff
offset and writing up tolen
characters.flush()
: This method flushes the output stream, forcing any buffered output to be written to the file.close()
: This method closes the output stream and releases any system resources associated with it.
Note that like all output stream classes, FileWriter
is designed to write characters to a stream one at a time. If you need to write a large amount of data at once, you may want to consider using a buffer or a higher-level class such as BufferedWriter
.