# FileOutputStream

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Ctors](https://developer.android.com/reference/java/io/FileOutputStream#pubctors)\|[Methods](https://developer.android.com/reference/java/io/FileOutputStream#pubmethods)\|[Protected Methods](https://developer.android.com/reference/java/io/FileOutputStream#promethods)\|[Inherited Methods](https://developer.android.com/reference/java/io/FileOutputStream#inhmethods)  

# FileOutputStream

`
public


class
FileOutputStream
`  
`


``

extends `[OutputStream](https://developer.android.com/reference/java/io/OutputStream)`


``


`

|---|---|--------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) |||
| ↳ | [java.io.OutputStream](https://developer.android.com/reference/java/io/OutputStream) ||
|   | ↳ | java.io.FileOutputStream |

|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Known direct subclasses [ParcelFileDescriptor.AutoCloseOutputStream](https://developer.android.com/reference/android/os/ParcelFileDescriptor.AutoCloseOutputStream) |---------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [ParcelFileDescriptor.AutoCloseOutputStream](https://developer.android.com/reference/android/os/ParcelFileDescriptor.AutoCloseOutputStream) | An OutputStream you can create on a ParcelFileDescriptor, which will take care of calling[ParcelFileDescriptor.close()](https://developer.android.com/reference/android/os/ParcelFileDescriptor#close())for you when the stream is closed. | |

|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Known indirect subclasses [AssetFileDescriptor.AutoCloseOutputStream](https://developer.android.com/reference/android/content/res/AssetFileDescriptor.AutoCloseOutputStream) |----------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [AssetFileDescriptor.AutoCloseOutputStream](https://developer.android.com/reference/android/content/res/AssetFileDescriptor.AutoCloseOutputStream) | An OutputStream you can create on a ParcelFileDescriptor, which will take care of calling[ParcelFileDescriptor.close()](https://developer.android.com/reference/android/os/ParcelFileDescriptor#close())for you when the stream is closed. | |

<br />

*** ** * ** ***

A file output stream is an output stream for writing data to a`File`or to a`FileDescriptor`. 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`FileOutputStream`(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.

`FileOutputStream`is meant for writing streams of raw bytes such as image data. For writing streams of characters, consider using`FileWriter`.  
**See also:**

- [File](https://developer.android.com/reference/java/io/File)
- [FileDescriptor](https://developer.android.com/reference/java/io/FileDescriptor)
- [FileInputStream](https://developer.android.com/reference/java/io/FileInputStream)
- [Files.newOutputStream(Path, OpenOption)](https://developer.android.com/reference/java/nio/file/Files#newOutputStream(java.nio.file.Path,%20java.nio.file.OpenOption[]))

## Summary

|                                                                                                                                                                                ### Public constructors                                                                                                                                                                                 ||
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[FileOutputStream](https://developer.android.com/reference/java/io/FileOutputStream#FileOutputStream(java.io.File))`(`[File](https://developer.android.com/reference/java/io/File)` file) ` Creates a file output stream to write to the file represented by the specified`File`object.                                                                                          |
| ` `[FileOutputStream](https://developer.android.com/reference/java/io/FileOutputStream#FileOutputStream(java.io.File,%20boolean))`(`[File](https://developer.android.com/reference/java/io/File)` file, boolean append) ` Creates a file output stream to write to the file represented by the specified`File`object.                                                               |
| ` `[FileOutputStream](https://developer.android.com/reference/java/io/FileOutputStream#FileOutputStream(java.io.FileDescriptor))`(`[FileDescriptor](https://developer.android.com/reference/java/io/FileDescriptor)` fdObj) ` Creates a file output stream to write to the specified file descriptor, which represents an existing connection to an actual file in the file system. |
| ` `[FileOutputStream](https://developer.android.com/reference/java/io/FileOutputStream#FileOutputStream(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` name) ` Creates a file output stream to write to the file with the specified name.                                                                                                 |
| ` `[FileOutputStream](https://developer.android.com/reference/java/io/FileOutputStream#FileOutputStream(java.lang.String,%20boolean))`(`[String](https://developer.android.com/reference/java/lang/String)` name, boolean append) ` Creates a file output stream to write to the file with the specified name.                                                                      |

|                                                                                                                                                                  ### Public methods                                                                                                                                                                  ||
|-------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` void`                                                                                   | ` `[close](https://developer.android.com/reference/java/io/FileOutputStream#close())`() ` Closes this file output stream and releases any system resources associated with this stream.                                                                   |
| ` `[FileChannel](https://developer.android.com/reference/java/nio/channels/FileChannel)   | ` `[getChannel](https://developer.android.com/reference/java/io/FileOutputStream#getChannel())`() ` Returns the unique[FileChannel](https://developer.android.com/reference/java/nio/channels/FileChannel)object associated with this file output stream. |
| ` final `[FileDescriptor](https://developer.android.com/reference/java/io/FileDescriptor) | ` `[getFD](https://developer.android.com/reference/java/io/FileOutputStream#getFD())`() ` Returns the file descriptor associated with this stream.                                                                                                        |
| ` void`                                                                                   | ` `[write](https://developer.android.com/reference/java/io/FileOutputStream#write(byte[]))`(byte[] b) ` Writes`b.length`bytes from the specified byte array to this file output stream.                                                                   |
| ` void`                                                                                   | ` `[write](https://developer.android.com/reference/java/io/FileOutputStream#write(byte[],%20int,%20int))`(byte[] b, int off, int len) ` Writes`len`bytes from the specified byte array starting at offset`off`to this file output stream.                 |
| ` void`                                                                                   | ` `[write](https://developer.android.com/reference/java/io/FileOutputStream#write(int))`(int b) ` Writes the specified byte to this file output stream.                                                                                                   |

|                                                                                                                          ### Protected methods                                                                                                                          ||
|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` void` | ` `[finalize](https://developer.android.com/reference/java/io/FileOutputStream#finalize())`() ` Cleans up the connection to the file, and ensures that the`close`method of this file output stream is called when there are no more references to this stream. |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.io.OutputStream](https://developer.android.com/reference/java/io/OutputStream)` ` |----------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` void`                                                                                | ` `[close](https://developer.android.com/reference/java/io/OutputStream#close())`() ` Closes this output stream and releases any system resources associated with this stream.                                                   | | ` void`                                                                                | ` `[flush](https://developer.android.com/reference/java/io/OutputStream#flush())`() ` Flushes this output stream and forces any buffered output bytes to be written out.                                                         | | ` static `[OutputStream](https://developer.android.com/reference/java/io/OutputStream) | ` `[nullOutputStream](https://developer.android.com/reference/java/io/OutputStream#nullOutputStream())`() ` Returns a new`OutputStream`which discards all bytes.                                                                 | | ` void`                                                                                | ` `[write](https://developer.android.com/reference/java/io/OutputStream#write(byte[]))`(byte[] b) ` Writes`b.length`bytes from the specified byte array to this output stream.                                                   | | ` void`                                                                                | ` `[write](https://developer.android.com/reference/java/io/OutputStream#write(byte[],%20int,%20int))`(byte[] b, int off, int len) ` Writes`len`bytes from the specified byte array starting at offset`off`to this output stream. | | ` abstract void`                                                                       | ` `[write](https://developer.android.com/reference/java/io/OutputStream#write(int))`(int b) ` Writes the specified byte to this output stream.                                                                                   | ||
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||
| From interface` `[java.io.Closeable](https://developer.android.com/reference/java/io/Closeable)` ` |------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract void` | ` `[close](https://developer.android.com/reference/java/io/Closeable#close())`() ` Closes this stream and releases any system resources associated with it. | ||
| From interface` `[java.io.Flushable](https://developer.android.com/reference/java/io/Flushable)` ` |------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract void` | ` `[flush](https://developer.android.com/reference/java/io/Flushable#flush())`() ` Flushes this stream by writing any buffered output to the underlying stream. | ||
| From interface` `[java.lang.AutoCloseable](https://developer.android.com/reference/java/lang/AutoCloseable)` ` |------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract void` | ` `[close](https://developer.android.com/reference/java/lang/AutoCloseable#close())`() ` Closes this resource, relinquishing any underlying resources. | ||

## Public constructors

### FileOutputStream

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public FileOutputStream (File file)
```

Creates a file output stream to write to the file represented by the specified`File`object. A new`FileDescriptor`object is created to represent this file connection.

First, if there is a security manager, its`checkWrite`method is called with the path represented by the`file`argument as its argument.

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 then a`FileNotFoundException`is thrown.

<br />

|                        Parameters                         ||
|--------|---------------------------------------------------|
| `file` | `File`: the file to be opened for writing. <br /> |

|                                                                                                                      Throws                                                                                                                      ||
|------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|
| [FileNotFoundException](https://developer.android.com/reference/java/io/FileNotFoundException) | 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 |
| [SecurityException](https://developer.android.com/reference/java/lang/SecurityException)       | if a security manager exists and its`checkWrite`method denies write access to the file.                                                          |

**See also:**

- [File.getPath()](https://developer.android.com/reference/java/io/File#getPath())
- [SecurityException](https://developer.android.com/reference/java/lang/SecurityException)
- [SecurityManager.checkWrite(java.lang.String)](https://developer.android.com/reference/java/lang/SecurityManager#checkWrite(java.lang.String))  

### FileOutputStream

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public FileOutputStream (File file, 
                boolean append)
```

Creates a file output stream to write to the file represented by the specified`File`object. If the second argument is`true`, then bytes will be written to the end of the file rather than the beginning. A new`FileDescriptor`object is created to represent this file connection.

First, if there is a security manager, its`checkWrite`method is called with the path represented by the`file`argument as its argument.

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 then a`FileNotFoundException`is thrown.

<br />

|                                                    Parameters                                                     ||
|----------|---------------------------------------------------------------------------------------------------------|
| `file`   | `File`: the file to be opened for writing. <br />                                                       |
| `append` | `boolean`: if`true`, then bytes will be written to the end of the file rather than the beginning <br /> |

|                                                                                                                      Throws                                                                                                                      ||
|------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|
| [FileNotFoundException](https://developer.android.com/reference/java/io/FileNotFoundException) | 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 |
| [SecurityException](https://developer.android.com/reference/java/lang/SecurityException)       | if a security manager exists and its`checkWrite`method denies write access to the file.                                                          |

**See also:**

- [File.getPath()](https://developer.android.com/reference/java/io/File#getPath())
- [SecurityException](https://developer.android.com/reference/java/lang/SecurityException)
- [SecurityManager.checkWrite(java.lang.String)](https://developer.android.com/reference/java/lang/SecurityManager#checkWrite(java.lang.String))  

### FileOutputStream

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public FileOutputStream (FileDescriptor fdObj)
```

Creates a file output stream to write to the specified file descriptor, which represents an existing connection to an actual file in the file system.

First, if there is a security manager, its`checkWrite`method is called with the file descriptor`fdObj`argument as its argument.

If`fdObj`is null then a`NullPointerException`is thrown.

This constructor does not throw an exception if`fdObj`is[invalid](https://developer.android.com/reference/java/io/FileDescriptor#valid()). However, if the methods are invoked on the resulting stream to attempt I/O on the stream, an`IOException`is thrown.

Android-specific warning:[close()](https://developer.android.com/reference/java/io/FileOutputStream#close())method doesn't close the`fdObj`provided, because this object doesn't own the file descriptor, but the caller does. The caller can call[Os.close(FileDescriptor)](https://developer.android.com/reference/android/system/Os#close(java.io.FileDescriptor))to close the fd.

<br />

|                                   Parameters                                   ||
|---------|-----------------------------------------------------------------------|
| `fdObj` | `FileDescriptor`: the file descriptor to be opened for writing <br /> |

|                                                                                           Throws                                                                                            ||
|------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------|
| [SecurityException](https://developer.android.com/reference/java/lang/SecurityException) | if a security manager exists and its`checkWrite`method denies write access to the file descriptor |

**See also:**

- [SecurityManager.checkWrite(java.io.FileDescriptor)](https://developer.android.com/reference/java/lang/SecurityManager#checkWrite(java.io.FileDescriptor))  

### FileOutputStream

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public FileOutputStream (String name)
```

Creates a file output stream to write to the file with the specified name. A new`FileDescriptor`object is created to represent this file connection.

First, if there is a security manager, its`checkWrite`method is called with`name`as its argument.

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 then a`FileNotFoundException`is thrown.

<br />

##### Implementation Requirements:

- Invoking this constructor with the parameter`name`is equivalent to invoking[new FileOutputStream(name, false)](https://developer.android.com/reference/java/io/FileOutputStream#FileOutputStream(java.lang.String,%20boolean)).

|                       Parameters                       ||
|--------|------------------------------------------------|
| `name` | `String`: the system-dependent filename <br /> |

|                                                                                                                      Throws                                                                                                                      ||
|------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|
| [FileNotFoundException](https://developer.android.com/reference/java/io/FileNotFoundException) | 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 |
| [SecurityException](https://developer.android.com/reference/java/lang/SecurityException)       | if a security manager exists and its`checkWrite`method denies write access to the file.                                                          |

**See also:**

- [SecurityManager.checkWrite(java.lang.String)](https://developer.android.com/reference/java/lang/SecurityManager#checkWrite(java.lang.String))  

### FileOutputStream

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public FileOutputStream (String name, 
                boolean append)
```

Creates a file output stream to write to the file with the specified name. If the second argument is`true`, then bytes will be written to the end of the file rather than the beginning. A new`FileDescriptor`object is created to represent this file connection.

First, if there is a security manager, its`checkWrite`method is called with`name`as its argument.

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 then a`FileNotFoundException`is thrown.

<br />

|                                                    Parameters                                                     ||
|----------|---------------------------------------------------------------------------------------------------------|
| `name`   | `String`: the system-dependent file name <br />                                                         |
| `append` | `boolean`: if`true`, then bytes will be written to the end of the file rather than the beginning <br /> |

|                                                                                                                      Throws                                                                                                                       ||
|------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------|
| [FileNotFoundException](https://developer.android.com/reference/java/io/FileNotFoundException) | 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. |
| [SecurityException](https://developer.android.com/reference/java/lang/SecurityException)       | if a security manager exists and its`checkWrite`method denies write access to the file.                                                           |

**See also:**

- [SecurityManager.checkWrite(java.lang.String)](https://developer.android.com/reference/java/lang/SecurityManager#checkWrite(java.lang.String))

## Public methods

### close

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void close ()
```

Closes this file output stream and releases any system resources associated with this stream. This file output stream may no longer be used for writing bytes.

If this stream has an associated channel then the channel is closed as well.

<br />

##### API Note:

- Overriding[close()](https://developer.android.com/reference/java/io/FileOutputStream#close())to perform cleanup actions is reliable only when called directly or when called by try-with-resources. Do not depend on finalization to invoke`close`; finalization is not reliable and is deprecated. If cleanup of native resources is needed, other mechanisms such as[Cleaner](https://developer.android.com/reference/java/lang/ref/Cleaner)should be used.

|                                               Throws                                                ||
|----------------------------------------------------------------------------|-------------------------|
| [IOException](https://developer.android.com/reference/java/io/IOException) | if an I/O error occurs. |

### getChannel

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public FileChannel getChannel ()
```

Returns the unique[FileChannel](https://developer.android.com/reference/java/nio/channels/FileChannel)object associated with this file output stream.

The initial[position](https://developer.android.com/reference/java/nio/channels/FileChannel#position())of the returned channel will be equal to the number of bytes written to the file so far unless this stream is in append mode, in which case it will be equal to the size of the file. Writing bytes to this stream will increment the channel's position accordingly. Changing the channel's position, either explicitly or by writing, will change this stream's file position.

<br />

|                                                                        Returns                                                                        ||
|--------------------------------------------------------------------------------------|-----------------------------------------------------------------|
| [FileChannel](https://developer.android.com/reference/java/nio/channels/FileChannel) | the file channel associated with this file output stream <br /> |

### getFD

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final FileDescriptor getFD ()
```

Returns the file descriptor associated with this stream.

<br />

|                                                                                                           Returns                                                                                                            ||
|----------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
| [FileDescriptor](https://developer.android.com/reference/java/io/FileDescriptor) | the`FileDescriptor`object that represents the connection to the file in the file system being used by this`FileOutputStream`object. <br /> |

|                                               Throws                                                ||
|----------------------------------------------------------------------------|-------------------------|
| [IOException](https://developer.android.com/reference/java/io/IOException) | if an I/O error occurs. |

**See also:**

- [FileDescriptor](https://developer.android.com/reference/java/io/FileDescriptor)  

### write

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void write (byte[] b)
```

Writes`b.length`bytes from the specified byte array to this file output stream.

<br />

|          Parameters           ||
|-----|--------------------------|
| `b` | `byte`: the data. <br /> |

|                                               Throws                                                ||
|----------------------------------------------------------------------------|-------------------------|
| [IOException](https://developer.android.com/reference/java/io/IOException) | if an I/O error occurs. |

### write

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void write (byte[] b, 
                int off, 
                int len)
```

Writes`len`bytes from the specified byte array starting at offset`off`to this file output stream.

<br />

|                     Parameters                     ||
|-------|---------------------------------------------|
| `b`   | `byte`: the data. <br />                    |
| `off` | `int`: the start offset in the data. <br /> |
| `len` | `int`: the number of bytes to write. <br /> |

|                                               Throws                                                ||
|----------------------------------------------------------------------------|-------------------------|
| [IOException](https://developer.android.com/reference/java/io/IOException) | if an I/O error occurs. |

### write

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void write (int b)
```

Writes the specified byte to this file output stream. Implements the`write`method of`OutputStream`.

<br />

|                 Parameters                 ||
|-----|---------------------------------------|
| `b` | `int`: the byte to be written. <br /> |

|                                               Throws                                                ||
|----------------------------------------------------------------------------|-------------------------|
| [IOException](https://developer.android.com/reference/java/io/IOException) | if an I/O error occurs. |

## Protected methods

### finalize

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
protected void finalize ()
```

Cleans up the connection to the file, and ensures that the`close`method of this file output stream is called when there are no more references to this stream.

<br />

|                                               Throws                                                ||
|----------------------------------------------------------------------------|-------------------------|
| [IOException](https://developer.android.com/reference/java/io/IOException) | if an I/O error occurs. |

**See also:**

- [FileInputStream.close()](https://developer.android.com/reference/java/io/FileInputStream#close())