Android 获取 Assets 文件

281 阅读1分钟
    public static JSONObject loadJsonFile(Context context, String fileName) throws IOException,
            JSONException {
        InputStream is = context.getAssets().open(fileName);
        int size = is.available();
        byte[] buffer = new byte[size];
        is.read(buffer);
        is.close();
        String jsonString = new String(buffer);
        return new JSONObject(jsonString);
    }