FileWriter (Java Platform SE 7 ) (original) (raw)
- java.io.Writer
- java.io.OutputStreamWriter
- java.io.FileWriter
- java.io.OutputStreamWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable
public class FileWriter
extends OutputStreamWriter
Convenience class for writing character files. The constructors of this class assume that the default character encoding and the default byte-buffer size are acceptable. To specify these values yourself, construct an OutputStreamWriter on a FileOutputStream.
Whether or not a file is available or may be created depends upon the underlying platform. Some platforms, in particular, allow a file to be opened for writing by only one FileWriter (or other file-writing object) at a time. In such situations the constructors in this class will fail if the file involved is already open.FileWriter
is meant for writing streams of characters. For writing streams of raw bytes, consider using aFileOutputStream
.
Since:
JDK1.1
See Also:
OutputStreamWriter, FileOutputStream
Field Summary
* ### Fields inherited from class java.io.[Writer](../../java/io/Writer.html "class in java.io") `[lock](../../java/io/Writer.html#lock)`
Constructor Summary
Constructors
Constructor and Description FileWriter(File file) Constructs a FileWriter object given a File object. FileWriter(File file, boolean append) Constructs a FileWriter object given a File object. FileWriter(FileDescriptor fd) Constructs a FileWriter object associated with a file descriptor. FileWriter(String fileName) Constructs a FileWriter object given a file name. FileWriter(String fileName, boolean append) Constructs a FileWriter object given a file name with a boolean indicating whether or not to append the data written. Method Summary
* ### Methods inherited from class java.io.[OutputStreamWriter](../../java/io/OutputStreamWriter.html "class in java.io") `[close](../../java/io/OutputStreamWriter.html#close%28%29), [flush](../../java/io/OutputStreamWriter.html#flush%28%29), [getEncoding](../../java/io/OutputStreamWriter.html#getEncoding%28%29), [write](../../java/io/OutputStreamWriter.html#write%28char[],%20int,%20int%29), [write](../../java/io/OutputStreamWriter.html#write%28int%29), [write](../../java/io/OutputStreamWriter.html#write%28java.lang.String,%20int,%20int%29)` * ### Methods inherited from class java.io.[Writer](../../java/io/Writer.html "class in java.io") `[append](../../java/io/Writer.html#append%28char%29), [append](../../java/io/Writer.html#append%28java.lang.CharSequence%29), [append](../../java/io/Writer.html#append%28java.lang.CharSequence,%20int,%20int%29), [write](../../java/io/Writer.html#write%28char[]%29), [write](../../java/io/Writer.html#write%28java.lang.String%29)` * ### Methods inherited from class java.lang.[Object](../../java/lang/Object.html "class in java.lang") `[clone](../../java/lang/Object.html#clone%28%29), [equals](../../java/lang/Object.html#equals%28java.lang.Object%29), [finalize](../../java/lang/Object.html#finalize%28%29), [getClass](../../java/lang/Object.html#getClass%28%29), [hashCode](../../java/lang/Object.html#hashCode%28%29), [notify](../../java/lang/Object.html#notify%28%29), [notifyAll](../../java/lang/Object.html#notifyAll%28%29), [toString](../../java/lang/Object.html#toString%28%29), [wait](../../java/lang/Object.html#wait%28%29), [wait](../../java/lang/Object.html#wait%28long%29), [wait](../../java/lang/Object.html#wait%28long,%20int%29)`
Constructor Detail
* #### FileWriter public FileWriter([String](../../java/lang/String.html "class in java.lang") fileName) throws [IOException](../../java/io/IOException.html "class in java.io") Constructs a FileWriter object given a file name. Parameters: `fileName` \- String The system-dependent filename. Throws: `[IOException](../../java/io/IOException.html "class in java.io")` \- if the named file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason * #### FileWriter public FileWriter([String](../../java/lang/String.html "class in java.lang") fileName, boolean append) throws [IOException](../../java/io/IOException.html "class in java.io") Constructs a FileWriter object given a file name with a boolean indicating whether or not to append the data written. Parameters: `fileName` \- String The system-dependent filename. `append` \- boolean if `true`, then data will be written to the end of the file rather than the beginning. Throws: `[IOException](../../java/io/IOException.html "class in java.io")` \- if the named file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason * #### FileWriter public FileWriter([File](../../java/io/File.html "class in java.io") file) throws [IOException](../../java/io/IOException.html "class in java.io") Constructs a FileWriter object given a File object. Parameters: `file` \- a File object to write to. Throws: `[IOException](../../java/io/IOException.html "class in java.io")` \- if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason * #### FileWriter public FileWriter([File](../../java/io/File.html "class in java.io") file, boolean append) throws [IOException](../../java/io/IOException.html "class in java.io") Constructs a FileWriter object given a File object. If the second argument is `true`, then bytes will be written to the end of the file rather than the beginning. Parameters: `file` \- a File object to write to `append` \- if `true`, then bytes will be written to the end of the file rather than the beginning Throws: `[IOException](../../java/io/IOException.html "class in java.io")` \- if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason Since: 1.4 * #### FileWriter public FileWriter([FileDescriptor](../../java/io/FileDescriptor.html "class in java.io") fd) Constructs a FileWriter object associated with a file descriptor. Parameters: `fd` \- FileDescriptor object to write to.
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2020, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.