Name
FileWriter
Synopsis
FileWriter is a
convenience subclass of OutputStreamWriter that is
useful when you want to write text (as opposed to binary data) to a
file. You create a FileWriter by specifying the
file to be written to and, optionally, whether the data should be
appended to the end of an existing file instead of overwriting that
file. The FileWriter class creates an internal
FileOutputStream to write bytes to the specified
file and uses the functionality of its superclass,
OutputStreamWriter, to convert the Unicode
characters written to the stream into bytes using the default
encoding of the default locale. (If you want to use an encoding other
than the default, you cannot use FileWriter; in
that case you must create your own
OutputStreamWriter and
FileOutputStream.) Because
FileWriter is a trivial subclass of
OutputStreamWriter, it does not define any methods
of its own, but simply inherits them from its superclass.
Figure 9-20. java.io.FileWriter
public class FileWriter extends OutputStreamWriter { // Public Constructors public FileWriter(File file) throws IOException; public FileWriter(FileDescriptor fd); public FileWriter(String fileName) throws IOException; 1.4 public FileWriter(File file, boolean append) throws IOException; public FileWriter(String fileName, boolean append) throws IOException; }
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access