Created
January 30, 2016 13:07
-
-
Save c0rp-aubakirov/beaf6d51b100557d1d9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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