首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

android tips:从资源文件中读取资料流显示

2012-09-13 
android tips:从资源文件中读取文件流显示在android中,假如有的文本文件,比如TXT放在raw下,要直接读取出来

android tips:从资源文件中读取文件流显示
在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这个就可以了

热点排行