首页 > 移动平台 > 详细

文件_ _android从资源文件中读取文件流并显示的方法

时间:2016-04-08 00:49:42      阅读:205      评论:0      收藏:0      [点我收藏+]

 

======== 1   android从资源文件中读取文件流并显示的方法。 

在android中,假如有的文本文件,比如TXT放在raw下,要直接读取出来,放到屏幕中显示,可以这样:

private void doRaw(){
  InputStream is = this.getResources().openRawResource(R.raw.ziliao);
  try{
    doRead(is);
  }catch(IOException e){
    e.printStackTrace();
  }
}
private void doRead(InputStream is) throws IOException{
  DataInputStream dis = new DataInputStream(is);
  byte[]buffer = new byte[is.available()];
  dis.readFully(buffer); 
  textView.setText(new String(buffer));
  dis.close();
  is.close();
}
//就是用this.getResources().openRawResource这个就可以了

 

文件_ _android从资源文件中读取文件流并显示的方法

原文:http://www.cnblogs.com/awkflf11/p/5366241.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!