android tips:从资源文件中读取文件流显示
2013-07-01 17:40
260 查看
在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这个就可以了
屏幕中显示,可以这样:
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从资源文件中读取文件流显示
- android从资源文件中读取文件流并显示的方法
- 文件_ _android从资源文件中读取文件流并显示的方法
- android从资源文件中读取文件流显示
- android从资源文件中读取文件流显示
- [AndroidTips]jni读取assets资源文件
- 解析Android资源文件及他们的读取方法详解
- 从零开始Android游戏编程(第二版)第十三章 读取游戏资源文件
- android读取txt文本资源文件
- Android从资源文件中读取文件全
- 使用adb pull命令从android系统中读取文件失败。显示:Permission denied
- 【android-tips】关于android应用R文件无法读取
- Android资源管理——资源文件的创建、读取和管理
- Android读取SD卡文件并显示到textview中
- Android高德地图开发--读取解析KML文件并显示在地图上
- 详谈Android从文件读取图像显示的效率问题
- displaytag中列名显示为中文(从资源文件中读取)
- android常见问题之jni读取assets资源文件
- Android apk安装过程及Java、JNI读取安装包内assets资源文件的两种方法(附源码实例)
- (转)android常见问题之jni读取assets资源文件(附源码)