I'm writing my first Android application, and I'm trying to read a res/raw
resource file.
The following code throws
a FileNotFound
Exception:
AssetFileDescriptor fd = res.openRawResourceFd(R.raw.myfile);
but this line of code works:
InputStream stream = res.openRawResource (R.raw.myfile);
I need the AssetFileDescriptor
in order to determine the length of the file. Any ideas why it isn't working?
You can do it this way:
FileDescriptor fd = getResources().openRawResourceFd(R.raw.rawResourceId).getFileDescriptor();
No try/catch block required.
This works;
AssetFileDescriptor afd = res.openRawResourceFd(R.raw.rawResourceId);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With