I know how to use the AssetManager
to read a File
from the res/raw
directory with an InputStream
, but for my special use
You can get a FileInputStream
to a resource in your assets like this:
AssetFileDescriptor fileDescriptor = assetManager.openFd(fileName);
FileInputStream stream = fileDescriptor.createInputStream();
The fileName
you supply to openFd()
should be the relative path to the asset, the same fileName
you would supply to open()
.
Alternatively you can also create the FileInputStream
like this:
AssetFileDescriptor assetFileDescriptor = assetManager.openFd(fileName);
FileDescriptor fileDescriptor = assetFileDescriptor.getFileDescriptor();
FileInputStream stream = new FileInputStream(fileDescriptor);