在android中,假如有的文本文件,比如TXT放在raw下,要直接读取出来,放到屏幕中显示,可以这样:
[代码] [Java]代码
01
private void doRaw(){
02
InputStream is = this.getResources().openRawResource(R.raw.ziliao);
03
try{
04
doRead(is);
05
}catch(IOException e){
06
e.printStackTrace();
07
}
08
}
09
private void doRead(InputStream is) throws IOException{
10
DataInputStream dis = new DataInputStream(is);
11
byte[]buffer = new byte[is.available()];
12
dis.readFully(buffer);
13
textView.setText(new String(buffer));
14
dis.close();
15
is.close();
16
}
17
18
//就是用this.getResources().openRawResource这个就可以了