Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public List<Month> months = new ArrayList<Month>();
- public void saveMonths(Context context) {
- Gson gson = new Gson();
- String gsonOutput = gson.toJson(this.months, ArrayList.class);
- FileOutputStream fos;
- try {
- if (context.getFileStreamPath(MONTHS_FILE).exists())
- context.deleteFile(MONTHS_FILE);
- fos = context.openFileOutput(MONTHS_FILE, Context.MODE_PRIVATE);
- fos.write(gsonOutput.getBytes());
- fos.close();
- } catch (FileNotFoundException e) {
- Log.e(e);
- } catch (IOException e) {
- Log.e(e);
- }
- }
- public void restoreMonths(Context context) {
- Gson gson = new Gson();
- try {
- this.months = gson.fromJson(new InputStreamReader(context.openFileInput(MONTHS_FILE)), new TypeToken<List<Month>>() {
- }.getType());
- } catch (JsonSyntaxException e) {
- Log.e(e);
- } catch (JsonIOException e) {
- Log.e(e);
- } catch (FileNotFoundException e) {
- Log.e(e);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement