我正在编写我的第一个Android应用程序,并且试图读取res/raw
资源文件。
以下代码throws
成为FileNotFound
异常:
AssetFileDescriptor fd = res.openRawResourceFd(R.raw.myfile);
但是这行代码有效:
InputStream stream = res.openRawResource (R.raw.myfile);
我需要
AssetFileDescriptor
来确定文件的长度。任何想法为什么它不起作用? 最佳答案
您可以这样操作:
FileDescriptor fd = getResources().openRawResourceFd(R.raw.rawResourceId).getFileDescriptor();
不需要try/catch块。