Android之assets资源

assets目录下存放的原生资源文件,通过getAssets()方法获取.

使用:

InputStream inputStream;
            try {
                inputStream = getAssets().open("data/chat.isp");
                String json = StringUtil.readTextFile(inputStream);
                JSONArray array = new JSONArray(json);
                backModel result = null;
                for (int i = 0; i < array.length(); i++) {
                    result = new backModel();
                    result.setTime(array.getJSONObject(i).getString("time"));
                    result.setContent(array.getJSONObject(i).getString("content"));
                    
backModels.add(result);
                }
            } catch (IOException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }

其中数据存在于assetsdatachat.isp文件中:

[{"time":"14:25:29","content":"在么?,","type":"1"},{"time":"14:26:18","content":"嗯,在的,","type":"2"}]

可以存储一些不更改的不用编译的数据

原文地址:https://www.cnblogs.com/zhangs1986/p/4733814.html