[Solved] Android Saving JSON response in Sharedpreferences


Use this class for your purpose with files ! Hope it will help you !

 public class MyJSON {

        static String fileName = "myBlog.json";

        public static void saveData(Context context, String mJsonResponse) {
            try {
                FileWriter file = new FileWriter(context.getFilesDir().getPath() + "https://stackoverflow.com/" + fileName);
                file.write(mJsonResponse);
                file.flush();
                file.close();
            } catch (IOException e) {
                Log.e("TAG", "Error in Writing: " + e.getLocalizedMessage());
            }
        }

        public static String getData(Context context) {
            try {
                File f = new File(context.getFilesDir().getPath() + "https://stackoverflow.com/" + fileName);
                //check whether file exists
                FileInputStream is = new FileInputStream(f);
                int size = is.available();
                byte[] buffer = new byte[size];
                is.read(buffer);
                is.close();
                return new String(buffer);
            } catch (IOException e) {
                Log.e("TAG", "Error in Reading: " + e.getLocalizedMessage());
                return null;
            }
        }
    }

3

solved Android Saving JSON response in Sharedpreferences