AndroidはJsonをローカルに格納し、ローカルJsonを読み取ります.


/**
     *   json   
     * @param mActivity
     * @param filename
     * @param content
     */
    public static File dir = new File(Environment.getExternalStorageDirectory() + "/.Imageloader/json/");

    public static void saveToSDCard(Activity mActivity, String filename, String content) {
        String en = Environment.getExternalStorageState();
        //  SDCard  ,  SDCard               
        if (en.equals(Environment.MEDIA_MOUNTED)) {
            try {
                dir.mkdirs(); //create folders where write files
                File file = new File(dir, filename);

                OutputStream out = new FileOutputStream(file);
                out.write(content.getBytes());
                out.close();
                AppUtils.showToast(mActivity, "    ");
            } catch (Exception e) {
                e.printStackTrace();
                AppUtils.showToast(mActivity, "    ");
            }
        } else {
            //    SDCard             
            AppUtils.showToast(mActivity, "SDCard           ");
        }
    }

    /**
     *      json
     * @param mActivity
     * @param filename
     * @param content
     */
    public static String readTextFile(String filePath) {
        StringBuilder sb = new StringBuilder();
        try {
            File file = new File(dir + "/" + filePath);
            InputStream in = null;
            in = new FileInputStream(file);
            int tempbyte;
            while ((tempbyte = in.read()) != -1) {
                sb.append((char) tempbyte);
            }
            in.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return sb.toString();
    }

 
転載先:https://www.cnblogs.com/niray/p/3953059.html