Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/android/content/res/AssetFileDescriptor#nestedclasses) \| [Constants](https://developer.android.com/reference/android/content/res/AssetFileDescriptor#constants) \| [Inherited Constants](https://developer.android.com/reference/android/content/res/AssetFileDescriptor#inhconstants) \| [Fields](https://developer.android.com/reference/android/content/res/AssetFileDescriptor#lfields) \| [Ctors](https://developer.android.com/reference/android/content/res/AssetFileDescriptor#pubctors) \| [Methods](https://developer.android.com/reference/android/content/res/AssetFileDescriptor#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/content/res/AssetFileDescriptor#inhmethods)

# AssetFileDescriptor

*** ** * ** ***

` public class AssetFileDescriptor `   
` extends https://developer.android.com/reference/java/lang/Object ` ` implements https://developer.android.com/reference/java/io/Closeable, https://developer.android.com/reference/android/os/Parcelable `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.content.res.AssetFileDescriptor |

<br />

*** ** * ** ***

File descriptor of an entry in the AssetManager. This provides your own opened FileDescriptor that can be used to read the data, as well as the offset and length of that entry's data in the file.

## Summary

| ### Nested classes ||
|---|---|
| ` class` | `https://developer.android.com/reference/android/content/res/AssetFileDescriptor.AutoCloseInputStream` An InputStream you can create on a ParcelFileDescriptor, which will take care of calling `https://developer.android.com/reference/android/os/ParcelFileDescriptor#close()` for you when the stream is closed. |
| ` class` | `https://developer.android.com/reference/android/content/res/AssetFileDescriptor.AutoCloseOutputStream` An OutputStream you can create on a ParcelFileDescriptor, which will take care of calling `https://developer.android.com/reference/android/os/ParcelFileDescriptor#close()` for you when the stream is closed. |

| ### Constants ||
|---|---|
| `long` | `https://developer.android.com/reference/android/content/res/AssetFileDescriptor#UNKNOWN_LENGTH` Length used with `https://developer.android.com/reference/android/content/res/AssetFileDescriptor#AssetFileDescriptor(android.os.ParcelFileDescriptor,%20long,%20long)` and `https://developer.android.com/reference/android/content/res/AssetFileDescriptor#getDeclaredLength()` when a length has not been declared. |

### Inherited constants

From interface `https://developer.android.com/reference/android/os/Parcelable` `int` `https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR`

Descriptor bit used with `https://developer.android.com/reference/android/os/Parcelable#describeContents()`: indicates that the Parcelable object's flattened representation includes a file descriptor.
`int` `https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE`

Flag for use with `https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)`: the object being written is a return value, that is the result of a function such as "`Parcelable someFunction()`", "`void someFunction(out Parcelable)`", or "`void someFunction(inout Parcelable)`".

| ### Fields ||
|---|---|
| ` public static final https://developer.android.com/reference/android/os/Parcelable.Creator<https://developer.android.com/reference/android/content/res/AssetFileDescriptor>` | `https://developer.android.com/reference/android/content/res/AssetFileDescriptor#CREATOR` <br /> |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/content/res/AssetFileDescriptor#AssetFileDescriptor(android.os.ParcelFileDescriptor,%20long,%20long)(https://developer.android.com/reference/android/os/ParcelFileDescriptor fd, long startOffset, long length) ` Create a new AssetFileDescriptor from the given values. |
| ` https://developer.android.com/reference/android/content/res/AssetFileDescriptor#AssetFileDescriptor(android.os.ParcelFileDescriptor,%20long,%20long,%20android.os.Bundle)(https://developer.android.com/reference/android/os/ParcelFileDescriptor fd, long startOffset, long length, https://developer.android.com/reference/android/os/Bundle extras) ` Create a new AssetFileDescriptor from the given values. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/content/res/AssetFileDescriptor#close()() ` Convenience for calling `getParcelFileDescriptor().close()`. |
| ` https://developer.android.com/reference/java/io/FileInputStream` | ` https://developer.android.com/reference/android/content/res/AssetFileDescriptor#createInputStream()() ` Create and return a new auto-close input stream for this asset. |
| ` https://developer.android.com/reference/java/io/FileOutputStream` | ` https://developer.android.com/reference/android/content/res/AssetFileDescriptor#createOutputStream()() ` Create and return a new auto-close output stream for this asset. |
| ` int` | ` https://developer.android.com/reference/android/content/res/AssetFileDescriptor#describeContents()() ` Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. |
| ` long` | ` https://developer.android.com/reference/android/content/res/AssetFileDescriptor#getDeclaredLength()() ` Return the actual number of bytes that were declared when the AssetFileDescriptor was constructed. |
| ` https://developer.android.com/reference/android/os/Bundle` | ` https://developer.android.com/reference/android/content/res/AssetFileDescriptor#getExtras()() ` Returns any additional details that can be used to interpret the underlying file descriptor. |
| ` https://developer.android.com/reference/java/io/FileDescriptor` | ` https://developer.android.com/reference/android/content/res/AssetFileDescriptor#getFileDescriptor()() ` Returns the FileDescriptor that can be used to read the data in the file. |
| ` long` | ` https://developer.android.com/reference/android/content/res/AssetFileDescriptor#getLength()() ` Returns the total number of bytes of this asset entry's data. |
| ` https://developer.android.com/reference/android/os/ParcelFileDescriptor` | ` https://developer.android.com/reference/android/content/res/AssetFileDescriptor#getParcelFileDescriptor()() ` The AssetFileDescriptor contains its own ParcelFileDescriptor, which in addition to the normal FileDescriptor object also allows you to close the descriptor when you are done with it. |
| ` long` | ` https://developer.android.com/reference/android/content/res/AssetFileDescriptor#getStartOffset()() ` Returns the byte offset where this asset entry's data starts. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/content/res/AssetFileDescriptor#toString()() ` Returns a string representation of the object. |
| ` void` | ` https://developer.android.com/reference/android/content/res/AssetFileDescriptor#writeToParcel(android.os.Parcel,%20int)(https://developer.android.com/reference/android/os/Parcel out, int flags) ` Flatten this object in to a Parcel. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` 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 https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` 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` ` 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` ` 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 ` https://developer.android.com/reference/java/io/Closeable ` ` abstract void` ` https://developer.android.com/reference/java/io/Closeable#close()() `

Closes this stream and releases any system resources associated with it.
From interface ` https://developer.android.com/reference/android/os/Parcelable ` ` abstract int` ` https://developer.android.com/reference/android/os/Parcelable#describeContents()() `

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.
` abstract void` ` https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)(https://developer.android.com/reference/android/os/Parcel dest, int flags) `

Flatten this object in to a Parcel.
From interface ` https://developer.android.com/reference/java/lang/AutoCloseable ` ` abstract void` ` https://developer.android.com/reference/java/lang/AutoCloseable#close()() `

Closes this resource, relinquishing any underlying resources.

## Constants

### UNKNOWN_LENGTH

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

```
public static final long UNKNOWN_LENGTH
```

Length used with `https://developer.android.com/reference/android/content/res/AssetFileDescriptor#AssetFileDescriptor(android.os.ParcelFileDescriptor,%20long,%20long)` and `https://developer.android.com/reference/android/content/res/AssetFileDescriptor#getDeclaredLength()` when a length has not been declared. This means the data extends to the end of the file.

<br />

Constant Value: -1 (0xffffffffffffffff)

## Fields

### CREATOR

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

```
public static final Creator<AssetFileDescriptor> CREATOR
```

<br />

<br />

## Public constructors

### AssetFileDescriptor

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

```
public AssetFileDescriptor (ParcelFileDescriptor fd, 
                long startOffset, 
                long length)
```

Create a new AssetFileDescriptor from the given values.

<br />

| Parameters ||
|---|---|
| `fd` | `ParcelFileDescriptor`: The underlying file descriptor. <br /> |
| `startOffset` | `long`: The location within the file that the asset starts. This must be 0 if length is UNKNOWN_LENGTH. <br /> |
| `length` | `long`: The number of bytes of the asset, or `https://developer.android.com/reference/android/content/res/AssetFileDescriptor#UNKNOWN_LENGTH` if it extends to the end of the file. <br /> |

### AssetFileDescriptor

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

```
public AssetFileDescriptor (ParcelFileDescriptor fd, 
                long startOffset, 
                long length, 
                Bundle extras)
```

Create a new AssetFileDescriptor from the given values.

<br />

| Parameters ||
|---|---|
| `fd` | `ParcelFileDescriptor`: The underlying file descriptor. <br /> |
| `startOffset` | `long`: The location within the file that the asset starts. This must be 0 if length is UNKNOWN_LENGTH. <br /> |
| `length` | `long`: The number of bytes of the asset, or `https://developer.android.com/reference/android/content/res/AssetFileDescriptor#UNKNOWN_LENGTH` if it extends to the end of the file. <br /> |
| `extras` | `Bundle`: additional details that can be used to interpret the underlying file descriptor. May be null. <br /> |

## Public methods

### close

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

```
public void close ()
```

Convenience for calling `getParcelFileDescriptor().close()`.

<br />

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` |   |

### createInputStream

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

```
public FileInputStream createInputStream ()
```

Create and return a new auto-close input stream for this asset. This will either return a full asset `https://developer.android.com/reference/android/content/res/AssetFileDescriptor.AutoCloseInputStream`, or an underlying `https://developer.android.com/reference/android/os/ParcelFileDescriptor.AutoCloseInputStream` depending on whether the the object represents a complete file or sub-section of a file. You should only call this once for a particular asset.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/io/FileInputStream` | <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` |   |

### createOutputStream

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

```
public FileOutputStream createOutputStream ()
```

Create and return a new auto-close output stream for this asset. This will either return a full asset `https://developer.android.com/reference/android/content/res/AssetFileDescriptor.AutoCloseOutputStream`, or an underlying `https://developer.android.com/reference/android/os/ParcelFileDescriptor.AutoCloseOutputStream` depending on whether the the object represents a complete file or sub-section of a file. You should only call this once for a particular asset.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/io/FileOutputStream` | <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` |   |

### describeContents

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

```
public int describeContents ()
```

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. For example, if the object will include a file descriptor in the output of `https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)`, the return value of this method must include the `https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR` bit.

<br />

| Returns ||
|---|---|
| `int` | a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either `0` or - `https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR` |

### getDeclaredLength

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

```
public long getDeclaredLength ()
```

Return the actual number of bytes that were declared when the AssetFileDescriptor was constructed. Will be `https://developer.android.com/reference/android/content/res/AssetFileDescriptor#UNKNOWN_LENGTH` if the length was not declared, meaning data should be read to the end of the file.

<br />

| Returns ||
|---|---|
| `long` | <br /> |

**See also:**

- `https://developer.android.com/reference/android/content/res/AssetFileDescriptor#getDeclaredLength()`

### getExtras

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

```
public Bundle getExtras ()
```

Returns any additional details that can be used to interpret the underlying file descriptor. May be null.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/Bundle` | <br /> |

### getFileDescriptor

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

```
public FileDescriptor getFileDescriptor ()
```

Returns the FileDescriptor that can be used to read the data in the file.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/io/FileDescriptor` | <br /> |

### getLength

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

```
public long getLength ()
```

Returns the total number of bytes of this asset entry's data. May be `https://developer.android.com/reference/android/content/res/AssetFileDescriptor#UNKNOWN_LENGTH` if the asset extends to the end of the file. If the AssetFileDescriptor was constructed with `https://developer.android.com/reference/android/content/res/AssetFileDescriptor#UNKNOWN_LENGTH`, this will use `https://developer.android.com/reference/android/os/ParcelFileDescriptor#getStatSize()` to find the total size of the file, returning that number if found or `https://developer.android.com/reference/android/content/res/AssetFileDescriptor#UNKNOWN_LENGTH` if it could not be determined.

<br />

| Returns ||
|---|---|
| `long` | <br /> |

**See also:**

- `https://developer.android.com/reference/android/content/res/AssetFileDescriptor#getDeclaredLength()`

### getParcelFileDescriptor

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

```
public ParcelFileDescriptor getParcelFileDescriptor ()
```

The AssetFileDescriptor contains its own ParcelFileDescriptor, which in addition to the normal FileDescriptor object also allows you to close the descriptor when you are done with it.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/ParcelFileDescriptor` | <br /> |

### getStartOffset

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

```
public long getStartOffset ()
```

Returns the byte offset where this asset entry's data starts.

<br />

| Returns ||
|---|---|
| `long` | <br /> |

### toString

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

```
public String toString ()
```

Returns a string representation of the object.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | a string representation of the object. <br /> |

### writeToParcel

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

```
public void writeToParcel (Parcel out, 
                int flags)
```

Flatten this object in to a Parcel.

<br />

| Parameters ||
|---|---|
| `out` | `Parcel`: The Parcel in which the object should be written. This value cannot be `null`. <br /> |
| `flags` | `int`: Additional flags about how the object should be written. May be 0 or `https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE`. Value is either `0` or a combination of the following: - `https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE` |