我知道如何使用AssetManager在InputStream中从res/raw目录读取文件,但对于特殊用例,需要文件输入。 特别需要文件输入流的原因是需要通过调用获取getChannel (文件通道) )
这是我到目前为止的代码,从文件中读取数据。 在我的例子中是基元的列表。
公共静态int [ ] loadbymappedbuffer (context context,String filename ) throws IOException{ )。
fileinputstreamfis=context.openfile input (filename;
文件信道ch=fis.get channel (;
mappedbytebuffermbuff=ch.map (map mode.read _ only,0,ch.size ) );
intbufferibuff=mbuff.asintbuffer (;
int[]Array=newint[Ibuff.limit(] ();
Ibuff.get(Array;
fis.close (;
ch.close (;
返回阵列;
}
我试图从Uri创建文件,但这只会导致文件not found exception :
uri uri=uri.parse (Android.resource ://com.example.empty/raw/file );
filefile=newfile(uri.getpath ();
fileinputstreamfis=new file inputstream (file;
如何使res/raw目录中的文件可以检索文件输入流?