Advertisement
gwoodhouse

Untitled

Feb 27th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. static FileResponse loadFromFile(Context context) {
  2. BufferedReader reader = null;
  3. try {
  4. reader = new BufferedReader(
  5. new InputStreamReader(context.getAssets().open("File.json")));
  6.  
  7. String wholeBook = "";
  8. String line;
  9. while ((line = reader.readLine()) != null) {
  10. wholeBook += line;
  11. }
  12.  
  13. return new Gson().fromJson(wholeBook, FileResponse.class);
  14. } catch (IOException e) {
  15. Logger.e(FileResponse.class.getSimpleName(), e.getMessage());
  16. } finally {
  17. if (reader != null) {
  18. try {
  19. reader.close();
  20. } catch (IOException e) {
  21. Logger.e(FileResponse.class.getSimpleName(), e.getMessage());
  22. }
  23. }
  24. }
  25.  
  26. return null;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement