您的位置:首页 > 移动开发 > Android开发

android_读取assets中的图片和文本文档

2017-03-27 14:41 459 查看
图片

try {

InputStream in = this.getAssets().open("p002.bmp");

Bitmap bm = BitmapFactory.decodeStream(in);

in.close();

in = null;

iv.setImageBitmap(bm);

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

文本文档

try {

InputStream fis = this.getAssets().open("jz.txt");

   

int count = fis.available();

byte[] bytes = new byte[count];

int len=0;

while((len=fis.read(bytes))!=-1){

System.out.println(len);

aa=aa+new String(bytes,0,len);

}

b.setText(aa);

fis.close();

fis = null;

} catch (IOException e) {

e.printStackTrace();

}

不要忘记加权限
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: