Android 读取raw文件

2019-12-23  本文已影响0人  山上的神仙

读取资源文件最好了,比如地区,放在apk进行一起打包读取。比如放在raw目录
别用String去+ 这样会浪费内存,就用stringbuilder最好

 public String getRawFile() {
        InputStream is = BaseApplication.getInstance().getApplication().getResources().openRawResource(R.raw.area);
        InputStreamReader isr = new InputStreamReader(is);
        StringBuilder result = new StringBuilder();
        BufferedReader bufferedReader = new BufferedReader(isr);
        String line = "";
        try {
            while ((line = bufferedReader.readLine()) != null) {
                result.append(line);
            }
            return result.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
上一篇下一篇

猜你喜欢

热点阅读