Android 读取assets中的Json文件

//文件名称
private final static String fileName = "regison.json";




class DataThread extends Thread {

    @Override

    public void run() {

        addStr = getJson(fileName);

        Message msg = handler.obtainMessage(0);
        handler.sendMessage(msg);

    }

//读取方法

 public String getJson(String fileName) {

        StringBuilder stringBuilder = new StringBuilder();
        try {
            AssetManager assetManager = SelectAreaActivity.this.getAssets();
            BufferedReader bf = new BufferedReader(new InputStreamReader(
                    assetManager.open(fileName)));
            String line;
            while ((line = bf.readLine()) != null) {
                stringBuilder.append(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return stringBuilder.toString();
    }
}

你可能感兴趣的:(Android 读取assets中的Json文件)