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;
    
        }
    }
    
  • 相关阅读:
    上下文管理器
    创建项目与介绍(2)
    虚拟环境的安装(1)
    爬虫-selenium(14-2)扩展
    爬虫10-1(协程)
    Python3笔记038
    Python3笔记037
    Python3笔记036
    Python3笔记035
    Python3笔记034
  • 原文地址:https://www.cnblogs.com/zzerx/p/12566866.html
Copyright © 2011-2022 走看看