# FileWriter

public class **FileWriter** extends [OutputStreamWriter](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStreamWriter.html)  
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 a
`FileOutputStream`.

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStreamWriter.html`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FileOutputStream.html`

### Inherited Field Summary

From class [java.io.Writer](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html)

|---|---|---|
| protected [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [lock](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html#lock) | The object used to synchronize operations on this stream. |

### Public Constructor Summary

|---|---|
|   | [FileWriter](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FileWriter.html#FileWriter(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) fileName) Constructs a FileWriter object given a file name. |
|   | [FileWriter](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FileWriter.html#FileWriter(java.lang.String,%20boolean))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) fileName, boolean append) Constructs a FileWriter object given a file name with a boolean indicating whether or not to append the data written. |
|   | [FileWriter](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FileWriter.html#FileWriter(java.io.File))([File](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/File.html) file) Constructs a FileWriter object given a File object. |
|   | [FileWriter](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FileWriter.html#FileWriter(java.io.File,%20boolean))([File](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/File.html) file, boolean append) Constructs a FileWriter object given a File object. |
|   | [FileWriter](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FileWriter.html#FileWriter(java.io.FileDescriptor))([FileDescriptor](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FileDescriptor.html) fd) Constructs a FileWriter object associated with a file descriptor. |

### Inherited Method Summary

From class [java.io.OutputStreamWriter](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStreamWriter.html)

|---|---|
| void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStreamWriter.html#close())() Closes this writer. |
| void | [flush](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStreamWriter.html#flush())() Flushes this writer. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [getEncoding](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStreamWriter.html#getEncoding())() Returns the canonical name of the encoding used by this writer to convert characters to bytes, or null if this writer has been closed. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStreamWriter.html#write(int))(int oneChar) Writes the character `oneChar` to this writer. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStreamWriter.html#write(java.lang.String,%20int,%20int))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) str, int offset, int count) Writes `count` characters starting at `offset` in `str` to this writer. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStreamWriter.html#write(char[],%20int,%20int))(char\[\] buffer, int offset, int count) Writes `count` characters starting at `offset` in `buf` to this writer. |

From class [java.io.Writer](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html)

|---|---|
| [Writer](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html) | [append](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html#append(char))(char c) Appends the specified character to this writer. |
| [Writer](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html) | [append](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html#append(java.lang.CharSequence,%20int,%20int))([CharSequence](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/CharSequence.html) csq, int start, int end) Appends a subsequence of the specified character sequence to this writer. |
| [Writer](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html) | [append](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html#append(java.lang.CharSequence))([CharSequence](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/CharSequence.html) csq) Appends the specified character sequence to this writer. |
| abstract void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html#close())() Closes the stream, flushing it first. |
| abstract void | [flush](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html#flush())() Flushes the stream. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html#write(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) str) Writes a string. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html#write(int))(int c) Writes a single character. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html#write(java.lang.String,%20int,%20int))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) str, int off, int len) Writes a portion of a string. |
| abstract void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html#write(char[],%20int,%20int))(char\[\] cbuf, int off, int len) Writes a portion of an array of characters. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html#write(char[]))(char\[\] cbuf) Writes an array of characters. |

From class [java.lang.Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> | [getClass](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#getClass())() Returns the unique instance of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html` that represents this object's class. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |
| final void | [notify](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| final void | [notifyAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |

From interface [java.lang.Appendable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Appendable.html)

|---|---|
| abstract [Appendable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Appendable.html) | [append](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Appendable.html#append(char))(char c) Appends the specified character to this Appendable. |
| abstract [Appendable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Appendable.html) | [append](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Appendable.html#append(java.lang.CharSequence,%20int,%20int))([CharSequence](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/CharSequence.html) csq, int start, int end) Appends a subsequence of the specified character sequence to this Appendable. |
| abstract [Appendable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Appendable.html) | [append](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Appendable.html#append(java.lang.CharSequence))([CharSequence](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/CharSequence.html) csq) Appends the specified character sequence to this Appendable. |

From interface [java.io.Closeable](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Closeable.html)

|---|---|
| abstract void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Closeable.html#close())() Closes this stream and releases any system resources associated with it. |

From interface [java.io.Flushable](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Flushable.html)

|---|---|
| abstract void | [flush](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Flushable.html#flush())() Flushes this stream by writing any buffered output to the underlying stream. |

From interface [java.lang.AutoCloseable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/AutoCloseable.html)

|---|---|
| abstract void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/AutoCloseable.html#close())() Closes this resource, relinquishing any underlying resources. |

## Public Constructors

#### public
**FileWriter**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) fileName)

Constructs a FileWriter object given a file name.

##### Parameters

| fileName | String The system-dependent filename. |
|---|---|

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | 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 |
|---|---|

#### public
**FileWriter**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) fileName, boolean append)

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](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | 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 |
|---|---|

#### public
**FileWriter**
([File](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/File.html) file)

Constructs a FileWriter object given a File object.

##### Parameters

| file | a File object to write to. |
|---|---|

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | 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 |
|---|---|

#### public
**FileWriter**
([File](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/File.html) file, boolean append)

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](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | 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 |
|---|---|

#### public
**FileWriter**
([FileDescriptor](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FileDescriptor.html) fd)

Constructs a FileWriter object associated with a file descriptor.

##### Parameters

| fd | FileDescriptor object to write to. |
|---|---|