6

res/raw初めての Android アプリケーションを作成していて、リソース ファイルを読み込もうとしています。

次のコードthrowsFileNotFound例外です。

AssetFileDescriptor fd = res.openRawResourceFd(R.raw.myfile);

しかし、このコード行は機能します:

InputStream stream = res.openRawResource (R.raw.myfile);

AssetFileDescriptorファイルの長さを決定するために必要です。それが機能しない理由はありますか?

4

3 に答える 3

1

これは機能します。

AssetFileDescriptor afd = res.openRawResourceFd(R.raw.rawResourceId);
于 2015-11-08T23:43:59.023 に答える
0

myfile をアセット フォルダに移動して、これを試してください

try{
    AssetFileDescriptor descriptor = getAssets().openFd( "myfile" );
    FileDescriptor fd = descriptor.getFileDescriptor();
}
catch(Exception)
{

}

または、次のコードを使用して、resources/raw foder から RAW ファイルを開こうとすることもできます。

FileDescriptor fd = getResources().openRawResourceFd(R.raw.myfile).getFileDescriptor();
于 2011-11-22T05:32:50.540 に答える