zoukankan      html  css  js  c++  java
  • Android读取asstes文件、图片

    确认注册并获取读写权限之后

    public class AssetsReader {
    
    
        public static String getText(String fileName, Context context) {
            try {
                InputStreamReader inputReader = new InputStreamReader(context.getResources().getAssets().open(fileName));
                BufferedReader bufReader = new BufferedReader(inputReader);
                String line = "";
                String Result = "";
                while ((line = bufReader.readLine()) != null)
                    Result += line;
                return Result;
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
    
    
        public static Bitmap getImage(Context mContext, String fileName) {
            Bitmap image = null;
    
            AssetManager am = mContext.getAssets();
            try {
                InputStream is = am.open(fileName);
                image = BitmapFactory.decodeStream(is);
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return image;
    
        }
    }
    
  • 相关阅读:
    工具类-vim在shell中卡死的情况
    tomcat日志分类
    逻辑运算
    牛客练习赛29 F 算式子
    牛客练习赛29 B
    查询
    hdu 5984
    zoj 4057
    zoj 4056
    zoj 4054
  • 原文地址:https://www.cnblogs.com/zzerx/p/12566866.html
Copyright © 2011-2022 走看看