Gson gson = new Gson(); JsonReader reader = new JsonReader(new FileReader(filename)); List<Review> data = gson.fromJson(reader, REVIEW_TYPE);
Or
Write
String filename = "myfile.txt"; Vector v = new Vector(10.0f, 20.0f); Gson gson = new Gson(); String s = gson.toJson(v); FileOutputStream outputStream; try { outputStream = openFileOutput(filename, Context.MODE_PRIVATE); outputStream.write(s.getBytes()); outputStream.close(); } catch (Exception e) { e.printStackTrace(); }
Read
FileInputStream fis = context.openFileInput("myfile.txt", Context.MODE_PRIVATE); InputStreamReader isr = new InputStreamReader(fis); BufferedReader bufferedReader = new BufferedReader(isr); StringBuilder sb = new StringBuilder(); String line; while ((line = bufferedReader.readLine()) != null) { sb.append(line); } String json = sb.toString(); Gson gson = new Gson(); Vector v = gson.fromJson(json, Vector.class);
References
https://stackoverflow.com/questions/29965764/how-to-parse-json-file-with-gson
https://stackoverflow.com/questions/19459082/read-and-write-data-with-gson