首页 > 编程知识 正文

android,fileinputstream类

时间:2023-05-03 23:47:00 阅读:148246 作者:4695

我知道如何使用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目录中的文件可以检索文件输入流?

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。