Android 读取Assets中资源

 //读取文件

private static String getFromAssets(Context context, String fileName) {

String result = "";

try {

InputStream in = context.getResources().getAssets().open(fileName);

// 获取文件的字节数

int lenght = in.available();

// 创建byte数组

byte[] buffer = new byte[lenght];

// 将文件中的数据读到byte数组中

in.read(buffer);

result = EncodingUtils.getString(buffer, "UTF-8");

} catch (Exception e) {

e.printStackTrace();

}

return result;

}

//读取图片

  /*  

    * 从Assets中读取图片  

    */  

   private Bitmap getImageFromAssetsFile(String fileName)  

   {  

       Bitmap image = null;  

       AssetManager am = getResources().getAssets();  

       try  

       {  

           InputStream is = am.open(fileName);  

           image = BitmapFactory.decodeStream(is);  

           is.close();  

       }  

       catch (IOException e)  

       {  

           e.printStackTrace();  

       }  

   

       return image;  

   

   } 

原文地址:https://www.cnblogs.com/wangzehuaw/p/4447255.html