Android 读取 assets目录下的文件

来源:互联网 发布:sql写入一句话木马 编辑:程序博客网 时间:2024/05/16 18:21

Android 读取 assets目录下的文件


  1.  * 读取Assets文件夹中的文件或资源 
  2.  * @param context 
  3.  * @param fileName assets目录下的文件名 
  4.  * @return 
  5.  */ 
  6. public static Bitmap getImageFromAssetsFile(Context context, String fileName) {   
  7.     Bitmap image = null;   
  8.     AssetManager am = context.getResources().getAssets();   
  9.     try {   
  10.         InputStream is = am.open(fileName);   
  11.         image = BitmapFactory.decodeStream(is);   
  12.         is.close();   
  13.     } catch (IOException e) {   
  14.         e.printStackTrace();   
  15.     }   
  16.     return image;   

0 0
原创粉丝点击