Android 读取raw文件

读取资源文件最好了,比如地区,放在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 "";
    }

你可能感兴趣的:(Android 读取raw文件)