======== 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这个就可以了

 

相关文章:

  • 2021-12-03
  • 2021-04-29
  • 2022-12-23
  • 2022-12-23
  • 2022-02-25
  • 2022-12-23
猜你喜欢
  • 2021-06-29
  • 2022-12-23
  • 2021-10-02
  • 2021-07-09
  • 2021-08-10
  • 2021-07-19
  • 2022-02-14
相关资源
相似解决方案