Skip to content

Instantly share code, notes, and snippets.

@c0rp-aubakirov
Created January 30, 2016 13:07
Show Gist options
  • Save c0rp-aubakirov/beaf6d51b100557d1d9a to your computer and use it in GitHub Desktop.
Save c0rp-aubakirov/beaf6d51b100557d1d9a to your computer and use it in GitHub Desktop.
public static List<Message> readDocumentsFromFile() {
final List<Message> empty = new ArrayList<>();
final Gson gson = new GsonBuilder().create();
final Type listType = new TypeToken<List<CommonMessage>>() {
}.getType();
final File file = new File("/tmp/kznews.json");
try {
if (file.exists()) {
final FileReader fileReader = new FileReader(file);
final JsonReader reader = new JsonReader(fileReader);
List<Message> messages = gson.fromJson(reader, listType);
return messages;
}
} catch (IOException e) {
e.printStackTrace();
}
return empty;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment