# AssetManager

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/AssetManager#nestedclasses)\|[Constants](https://developer.android.com/reference/android/content/res/AssetManager#constants)\|[Methods](https://developer.android.com/reference/android/content/res/AssetManager#pubmethods)\|[Protected Methods](https://developer.android.com/reference/android/content/res/AssetManager#promethods)\|[Inherited Methods](https://developer.android.com/reference/android/content/res/AssetManager#inhmethods)  

# AssetManager

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/content/res/AssetManager "View this page in Kotlin")\|Java

`
public

final

class
AssetManager
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


implements

`[AutoCloseable](https://developer.android.com/reference/java/lang/AutoCloseable)`


`

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

<br />

*** ** * ** ***

Provides access to an application's raw asset files; see[Resources](https://developer.android.com/reference/android/content/res/Resources)for the way most applications will want to retrieve their resource data. This class presents a lower-level API that allows you to open and read raw files that have been bundled with the application as a simple stream of bytes.

## Summary

|                                                             ### Nested classes                                                              ||
|----------|-----------------------------------------------------------------------------------------------------------------------------------|
| ` class` | [AssetManager.AssetInputStream](https://developer.android.com/reference/android/content/res/AssetManager.AssetInputStream) <br /> |

|                                                                                                                                                       ### Constants                                                                                                                                                       ||
|-------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | [ACCESS_BUFFER](https://developer.android.com/reference/android/content/res/AssetManager#ACCESS_BUFFER) Mode for[open(java.lang.String, int)](https://developer.android.com/reference/android/content/res/AssetManager#open(java.lang.String,%20int)): Attempt to load contents into memory, for fast small reads. |
| `int` | [ACCESS_RANDOM](https://developer.android.com/reference/android/content/res/AssetManager#ACCESS_RANDOM) Mode for[open(java.lang.String, int)](https://developer.android.com/reference/android/content/res/AssetManager#open(java.lang.String,%20int)): Read chunks, and seek forward and backward.                 |
| `int` | [ACCESS_STREAMING](https://developer.android.com/reference/android/content/res/AssetManager#ACCESS_STREAMING) Mode for[open(java.lang.String, int)](https://developer.android.com/reference/android/content/res/AssetManager#open(java.lang.String,%20int)): Read sequentially, with an occasional forward seek.   |
| `int` | [ACCESS_UNKNOWN](https://developer.android.com/reference/android/content/res/AssetManager#ACCESS_UNKNOWN) Mode for[open(java.lang.String, int)](https://developer.android.com/reference/android/content/res/AssetManager#open(java.lang.String,%20int)): no specific information about how data will be accessed.  |

|                                                                                                                                                                                                                                                 ### Public methods                                                                                                                                                                                                                                                 ||
|-----------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` void`                                                                                                   | ` `[close](https://developer.android.com/reference/android/content/res/AssetManager#close())`() ` Close this asset manager.                                                                                                                                                                                                                                                                             |
| ` `[String[]](https://developer.android.com/reference/java/lang/String)                                   | ` `[getLocales](https://developer.android.com/reference/android/content/res/AssetManager#getLocales())`() ` Get the locales that this asset manager contains data for.                                                                                                                                                                                                                                  |
| ` `[String[]](https://developer.android.com/reference/java/lang/String)                                   | ` `[list](https://developer.android.com/reference/android/content/res/AssetManager#list(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` path) ` Return a String array of all the assets at the given path.                                                                                                                                                     |
| ` `[InputStream](https://developer.android.com/reference/java/io/InputStream)                             | ` `[open](https://developer.android.com/reference/android/content/res/AssetManager#open(java.lang.String,%20int))`(`[String](https://developer.android.com/reference/java/lang/String)` fileName, int accessMode) ` Open an asset using an explicit access mode, returning an InputStream to read its contents.                                                                                         |
| ` `[InputStream](https://developer.android.com/reference/java/io/InputStream)                             | ` `[open](https://developer.android.com/reference/android/content/res/AssetManager#open(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` fileName) ` Open an asset using ACCESS_STREAMING mode.                                                                                                                                                                 |
| ` `[AssetFileDescriptor](https://developer.android.com/reference/android/content/res/AssetFileDescriptor) | ` `[openFd](https://developer.android.com/reference/android/content/res/AssetManager#openFd(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` fileName) ` Open an uncompressed asset by mmapping it and returning an[AssetFileDescriptor](https://developer.android.com/reference/android/content/res/AssetFileDescriptor).                                      |
| ` `[AssetFileDescriptor](https://developer.android.com/reference/android/content/res/AssetFileDescriptor) | ` `[openNonAssetFd](https://developer.android.com/reference/android/content/res/AssetManager#openNonAssetFd(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` fileName) ` Open a non-asset as an asset by mmapping it and returning an[AssetFileDescriptor](https://developer.android.com/reference/android/content/res/AssetFileDescriptor).                    |
| ` `[AssetFileDescriptor](https://developer.android.com/reference/android/content/res/AssetFileDescriptor) | ` `[openNonAssetFd](https://developer.android.com/reference/android/content/res/AssetManager#openNonAssetFd(int,%20java.lang.String))`(int cookie, `[String](https://developer.android.com/reference/java/lang/String)` fileName) ` Open a non-asset as an asset by mmapping it and returning an[AssetFileDescriptor](https://developer.android.com/reference/android/content/res/AssetFileDescriptor). |
| ` `[XmlResourceParser](https://developer.android.com/reference/android/content/res/XmlResourceParser)     | ` `[openXmlResourceParser](https://developer.android.com/reference/android/content/res/AssetManager#openXmlResourceParser(int,%20java.lang.String))`(int cookie, `[String](https://developer.android.com/reference/java/lang/String)` fileName) ` Retrieve a parser for a compiled XML file.                                                                                                            |
| ` `[XmlResourceParser](https://developer.android.com/reference/android/content/res/XmlResourceParser)     | ` `[openXmlResourceParser](https://developer.android.com/reference/android/content/res/AssetManager#openXmlResourceParser(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` fileName) ` Retrieve a parser for a compiled XML file.                                                                                                                               |

|                                                                                                               ### Protected methods                                                                                                               ||
|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` void` | ` `[finalize](https://developer.android.com/reference/android/content/res/AssetManager#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. |

| ### Inherited methods |
|-----------------------|---|
| 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.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. | ||

## Constants

### ACCESS_BUFFER

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

```
public static final int ACCESS_BUFFER
```

Mode for[open(java.lang.String, int)](https://developer.android.com/reference/android/content/res/AssetManager#open(java.lang.String,%20int)): Attempt to load contents into memory, for fast small reads.

<br />

Constant Value: 3 (0x00000003)  

### ACCESS_RANDOM

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

```
public static final int ACCESS_RANDOM
```

Mode for[open(java.lang.String, int)](https://developer.android.com/reference/android/content/res/AssetManager#open(java.lang.String,%20int)): Read chunks, and seek forward and backward.

<br />

Constant Value: 1 (0x00000001)  

### ACCESS_STREAMING

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

```
public static final int ACCESS_STREAMING
```

Mode for[open(java.lang.String, int)](https://developer.android.com/reference/android/content/res/AssetManager#open(java.lang.String,%20int)): Read sequentially, with an occasional forward seek.

<br />

Constant Value: 2 (0x00000002)  

### ACCESS_UNKNOWN

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

```
public static final int ACCESS_UNKNOWN
```

Mode for[open(java.lang.String, int)](https://developer.android.com/reference/android/content/res/AssetManager#open(java.lang.String,%20int)): no specific information about how data will be accessed.

<br />

Constant Value: 0 (0x00000000)

## Public methods

### close

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

```
public void close ()
```

Close this asset manager.

<br />

### getLocales

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

```
public String[] getLocales ()
```

Get the locales that this asset manager contains data for.

On SDK 21 (Android 5.0: Lollipop) and above, Locale strings are valid[BCP-47](https://tools.ietf.org/html/bcp47)language tags and can be parsed using[Locale.forLanguageTag(String)](https://developer.android.com/reference/java/util/Locale#forLanguageTag(java.lang.String)).

On SDK 20 (Android 4.4W: KitKat for watches) and below, locale strings are of the form`ll_CC`where`ll`is a two letter language code, and`CC`is a two letter country code.

<br />

|                                   Returns                                    ||
|----------------------------------------------------------------------|--------|
| [String[]](https://developer.android.com/reference/java/lang/String) | <br /> |

### list

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

```
public String[] list (String path)
```

Return a String array of all the assets at the given path.

<br />

|                                                   Parameters                                                    ||
|--------|---------------------------------------------------------------------------------------------------------|
| `path` | `String`: A relative path within the assets, i.e., "docs/home.html". This value cannot be`null`. <br /> |

|                                                                                                                                                        Returns                                                                                                                                                         ||
|----------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [String[]](https://developer.android.com/reference/java/lang/String) | String\[\] Array of strings, one for each asset. These file names are relative to 'path'. You can open the file by concatenating 'path' and a name in the returned string (via File) and passing that to open(). This value may be`null`. <br /> |

|                                    Throws                                     ||
|----------------------------------------------------------------------------|---|
| [IOException](https://developer.android.com/reference/java/io/IOException) |   |

**See also:**

- [open(String)](https://developer.android.com/reference/android/content/res/AssetManager#open(java.lang.String))  

### open

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

```
public InputStream open (String fileName, 
                int accessMode)
```

Open an asset using an explicit access mode, returning an InputStream to read its contents. This provides access to files that have been bundled with an application as assets -- that is, files placed in to the "assets" directory.

<br />

|                                                        Parameters                                                        ||
|--------------|------------------------------------------------------------------------------------------------------------|
| `fileName`   | `String`: The name of the asset to open. This name can be hierarchical. This value cannot be`null`. <br /> |
| `accessMode` | `int`: Desired access mode for retrieving the data. <br />                                                 |

|                                                    Returns                                                     ||
|----------------------------------------------------------------------------|------------------------------------|
| [InputStream](https://developer.android.com/reference/java/io/InputStream) | This value cannot be`null`. <br /> |

|                                    Throws                                     ||
|----------------------------------------------------------------------------|---|
| [IOException](https://developer.android.com/reference/java/io/IOException) |   |

**See also:**

- [ACCESS_UNKNOWN](https://developer.android.com/reference/android/content/res/AssetManager#ACCESS_UNKNOWN)
- [ACCESS_STREAMING](https://developer.android.com/reference/android/content/res/AssetManager#ACCESS_STREAMING)
- [ACCESS_RANDOM](https://developer.android.com/reference/android/content/res/AssetManager#ACCESS_RANDOM)
- [ACCESS_BUFFER](https://developer.android.com/reference/android/content/res/AssetManager#ACCESS_BUFFER)
- [open(String)](https://developer.android.com/reference/android/content/res/AssetManager#open(java.lang.String))
- [list(String)](https://developer.android.com/reference/android/content/res/AssetManager#list(java.lang.String))  

### open

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

```
public InputStream open (String fileName)
```

Open an asset using ACCESS_STREAMING mode. This provides access to files that have been bundled with an application as assets -- that is, files placed in to the "assets" directory.

<br />

|                                                       Parameters                                                       ||
|------------|------------------------------------------------------------------------------------------------------------|
| `fileName` | `String`: The name of the asset to open. This name can be hierarchical. This value cannot be`null`. <br /> |

|                                                    Returns                                                     ||
|----------------------------------------------------------------------------|------------------------------------|
| [InputStream](https://developer.android.com/reference/java/io/InputStream) | This value cannot be`null`. <br /> |

|                                    Throws                                     ||
|----------------------------------------------------------------------------|---|
| [IOException](https://developer.android.com/reference/java/io/IOException) |   |

**See also:**

- [open(String, int)](https://developer.android.com/reference/android/content/res/AssetManager#open(java.lang.String,%20int))
- [list(String)](https://developer.android.com/reference/android/content/res/AssetManager#list(java.lang.String))  

### openFd

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

```
public AssetFileDescriptor openFd (String fileName)
```

Open an uncompressed asset by mmapping it and returning an[AssetFileDescriptor](https://developer.android.com/reference/android/content/res/AssetFileDescriptor). This provides access to files that have been bundled with an application as assets -- that is, files placed in to the "assets" directory. The asset must be uncompressed, or an exception will be thrown.

<br />

|                                                       Parameters                                                       ||
|------------|------------------------------------------------------------------------------------------------------------|
| `fileName` | `String`: The name of the asset to open. This name can be hierarchical. This value cannot be`null`. <br /> |

|                                                                                 Returns                                                                                 ||
|--------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------|
| [AssetFileDescriptor](https://developer.android.com/reference/android/content/res/AssetFileDescriptor) | An open AssetFileDescriptor. This value cannot be`null`. <br /> |

|                                    Throws                                     ||
|----------------------------------------------------------------------------|---|
| [IOException](https://developer.android.com/reference/java/io/IOException) |   |

### openNonAssetFd

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

```
public AssetFileDescriptor openNonAssetFd (String fileName)
```

Open a non-asset as an asset by mmapping it and returning an[AssetFileDescriptor](https://developer.android.com/reference/android/content/res/AssetFileDescriptor). This provides direct access to all of the files included in an application package (not only its assets). Applications should not normally use this. The asset must not be compressed, or an exception will be thrown.

<br />

|                                       Parameters                                        ||
|------------|-----------------------------------------------------------------------------|
| `fileName` | `String`: Name of the asset to retrieve. This value cannot be`null`. <br /> |

|                                                                  Returns                                                                   ||
|--------------------------------------------------------------------------------------------------------|------------------------------------|
| [AssetFileDescriptor](https://developer.android.com/reference/android/content/res/AssetFileDescriptor) | This value cannot be`null`. <br /> |

|                                    Throws                                     ||
|----------------------------------------------------------------------------|---|
| [IOException](https://developer.android.com/reference/java/io/IOException) |   |

### openNonAssetFd

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

```
public AssetFileDescriptor openNonAssetFd (int cookie, 
                String fileName)
```

Open a non-asset as an asset by mmapping it and returning an[AssetFileDescriptor](https://developer.android.com/reference/android/content/res/AssetFileDescriptor). This provides direct access to all of the files included in an application package (not only its assets). Applications should not normally use this. The asset must not be compressed, or an exception will be thrown.

<br />

|                                       Parameters                                        ||
|------------|-----------------------------------------------------------------------------|
| `cookie`   | `int`: Identifier of the package to be opened. <br />                       |
| `fileName` | `String`: Name of the asset to retrieve. This value cannot be`null`. <br /> |

|                                                                  Returns                                                                   ||
|--------------------------------------------------------------------------------------------------------|------------------------------------|
| [AssetFileDescriptor](https://developer.android.com/reference/android/content/res/AssetFileDescriptor) | This value cannot be`null`. <br /> |

|                                    Throws                                     ||
|----------------------------------------------------------------------------|---|
| [IOException](https://developer.android.com/reference/java/io/IOException) |   |

### openXmlResourceParser

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

```
public XmlResourceParser openXmlResourceParser (int cookie, 
                String fileName)
```

Retrieve a parser for a compiled XML file.

<br />

|                                         Parameters                                         ||
|------------|--------------------------------------------------------------------------------|
| `cookie`   | `int`: Identifier of the package to be opened. <br />                          |
| `fileName` | `String`: The name of the file to retrieve. This value cannot be`null`. <br /> |

|                                                                Returns                                                                 ||
|----------------------------------------------------------------------------------------------------|------------------------------------|
| [XmlResourceParser](https://developer.android.com/reference/android/content/res/XmlResourceParser) | This value cannot be`null`. <br /> |

|                                    Throws                                     ||
|----------------------------------------------------------------------------|---|
| [IOException](https://developer.android.com/reference/java/io/IOException) |   |

### openXmlResourceParser

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

```
public XmlResourceParser openXmlResourceParser (String fileName)
```

Retrieve a parser for a compiled XML file.

<br />

|                                         Parameters                                         ||
|------------|--------------------------------------------------------------------------------|
| `fileName` | `String`: The name of the file to retrieve. This value cannot be`null`. <br /> |

|                                                                Returns                                                                 ||
|----------------------------------------------------------------------------------------------------|------------------------------------|
| [XmlResourceParser](https://developer.android.com/reference/android/content/res/XmlResourceParser) | This value cannot be`null`. <br /> |

|                                    Throws                                     ||
|----------------------------------------------------------------------------|---|
| [IOException](https://developer.android.com/reference/java/io/IOException) |   |

## Protected methods

### finalize

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

```
protected void finalize ()
```

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the`finalize`method to dispose of system resources or to perform other cleanup.

The general contract of`finalize`is that it is invoked if and when the Java virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The`finalize`method may take any action, including making this object available again to other threads; the usual purpose of`finalize`, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The`finalize`method of class`Object`performs no special action; it simply returns normally. Subclasses of`Object`may override this definition.

The Java programming language does not guarantee which thread will invoke the`finalize`method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the`finalize`method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The`finalize`method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the`finalize`method causes the finalization of this object to be halted, but is otherwise ignored.

<br />

|                                   Throws                                    ||
|--------------------------------------------------------------------------|---|
| [Throwable](https://developer.android.com/reference/java/lang/Throwable) |   |