AssetManager
public
final
class
AssetManager
extends Object
implements
AutoCloseable
| java.lang.Object | |
| ↳ | android.content.res.AssetManager |
Provides access to an application's raw asset files; see 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
|
Constants | |
|---|---|
int |
ACCESS_BUFFER
Mode for |
int |
ACCESS_RANDOM
Mode for |
int |
ACCESS_STREAMING
Mode for |
int |
ACCESS_UNKNOWN
Mode for |
Public methods | |
|---|---|
void
|
close()
Close this asset manager. |
String[]
|
getLocales()
Get the locales that this asset manager contains data for. |
String[]
|
list(String path)
Return a String array of all the assets at the given path. |
InputStream
|
open(String fileName, int accessMode)
Open an asset using an explicit access mode, returning an InputStream to read its contents. |
InputStream
|
open(String fileName)
Open an asset using ACCESS_STREAMING mode. |
AssetFileDescriptor
|
openFd(String fileName)
Open an uncompressed asset by mmapping it and returning an |
AssetFileDescriptor
|
openNonAssetFd(String fileName)
Open a non-asset as an asset by mmapping it and returning an |
AssetFileDescriptor
|
openNonAssetFd(int cookie, String fileName)
Open a non-asset as an asset by mmapping it and returning an |
XmlResourceParser
|
openXmlResourceParser(int cookie, String fileName)
Retrieve a parser for a compiled XML file. |
XmlResourceParser
|
openXmlResourceParser(String fileName)
Retrieve a parser for a compiled XML file. |
Inherited methods | |
|---|---|
Constants
ACCESS_BUFFER
public static final int ACCESS_BUFFER
Mode for open(String,int): Attempt to load contents into
memory, for fast small reads.
Constant Value: 3 (0x00000003)
ACCESS_RANDOM
public static final int ACCESS_RANDOM
Mode for open(String,int): Read chunks, and seek forward and
backward.
Constant Value: 1 (0x00000001)
ACCESS_STREAMING
public static final int ACCESS_STREAMING
Mode for open(String,int): Read sequentially, with an
occasional forward seek.
Constant Value: 2 (0x00000002)
ACCESS_UNKNOWN
public static final int ACCESS_UNKNOWN
Mode for open(String,int): no specific information about how
data will be accessed.
Constant Value: 0 (0x00000000)
Public methods
getLocales
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 language tags and can be
parsed using Locale.forLanguageTag(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.
| Returns | |
|---|---|
String[] |
|
list
public String[] list (String path)
Return a String array of all the assets at the given path.
| Parameters | |
|---|---|
path |
String: A relative path within the assets, i.e., "docs/home.html".
This value cannot be null. |
| Returns | |
|---|---|
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. |
| Throws | |
|---|---|
IOException |
|
See also:
open
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.
| Parameters | |
|---|---|
fileName |
String: The name of the asset to open. This name can be hierarchical.
This value cannot be null. |
accessMode |
int: Desired access mode for retrieving the data. |
| Returns | |
|---|---|
InputStream |
This value cannot be null. |
| Throws | |
|---|---|
IOException |
|
open
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.
| Parameters | |
|---|---|
fileName |
String: The name of the asset to open. This name can be hierarchical.
This value cannot be null. |
| Returns | |
|---|---|
InputStream |
This value cannot be null. |
| Throws | |
|---|---|
IOException |
|
See also:
openFd
public AssetFileDescriptor openFd (String fileName)
Open an uncompressed asset by mmapping it and returning an 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.
| Parameters | |
|---|---|
fileName |
String: The name of the asset to open. This name can be hierarchical.
This value cannot be null. |
| Returns | |
|---|---|
AssetFileDescriptor |
An open AssetFileDescriptor.
This value cannot be null. |
| Throws | |
|---|---|
IOException |
|
openNonAssetFd
public AssetFileDescriptor openNonAssetFd (String fileName)
Open a non-asset as an asset by mmapping it and returning an 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.
| Parameters | |
|---|---|
fileName |
String: Name of the asset to retrieve.
This value cannot be null. |
| Returns | |
|---|---|
AssetFileDescriptor |
This value cannot be null. |
| Throws | |
|---|---|
IOException |
|
openNonAssetFd
public AssetFileDescriptor openNonAssetFd (int cookie, String fileName)
Open a non-asset as an asset by mmapping it and returning an 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.
| Parameters | |
|---|---|
cookie |
int: Identifier of the package to be opened. |
fileName |
String: Name of the asset to retrieve.
This value cannot be null. |
| Returns | |
|---|---|
AssetFileDescriptor |
This value cannot be null. |
| Throws | |
|---|---|
IOException |
|
openXmlResourceParser
public XmlResourceParser openXmlResourceParser (int cookie, String fileName)
Retrieve a parser for a compiled XML file.
| Parameters | |
|---|---|
cookie |
int: Identifier of the package to be opened. |
fileName |
String: The name of the file to retrieve.
This value cannot be null. |
| Returns | |
|---|---|
XmlResourceParser |
This value cannot be null. |
| Throws | |
|---|---|
IOException |
|
openXmlResourceParser
public XmlResourceParser openXmlResourceParser (String fileName)
Retrieve a parser for a compiled XML file.
| Parameters | |
|---|---|
fileName |
String: The name of the file to retrieve.
This value cannot be null. |
| Returns | |
|---|---|
XmlResourceParser |
This value cannot be null. |
| Throws | |
|---|---|
IOException |
|
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2026-08-03 UTC.