zoukankan      html  css  js  c++  java
  • 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;  

       

       } 

  • 相关阅读:
    之所以菜鸟依旧
    单点登陆
    让entityframework.extend库同时支持mysql,sqlsever
    背包算法
    JS中实现继承
    Altium Designer 生成 Mach3 G代码的程序
    test博客嵌入pbi
    testPBI报表
    html中隐藏title属性方法
    Spring mvc 中有关 Shiro 1.2.3 配置问题
  • 原文地址:https://www.cnblogs.com/wangzehuaw/p/4447255.html
Copyright © 2011-2022 走看看