kd2bwzgen

The loading code

Feb 11th, 2016
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.58 KB | None | 0 0
  1.     public void load(){
  2.         File save = new File("<location of save>");
  3.         String gameson = null;
  4.         if (save.exists() && !save.isDirectory()) {
  5.             try(Scanner scanner = new Scanner("<location of save>")){
  6.                 String temp = scanner.nextLine();
  7.                 while (scanner.hasNext()) {
  8.                     temp = temp + scanner.nextLine();
  9.                 }
  10.                 gameson = temp;
  11.             } catch (Exception e) {
  12.                 e.printStackTrace();
  13.             }
  14.             Gson gson = new GsonBuilder().create();
  15.             savedGame = gson.fromJson(gameson, me.minerobber9000.ircadventure.game.Game.class);
  16.         } else {
  17.             System.out.println("No save to load.");
  18.         }
  19.     }
Advertisement
Add Comment
Please, Sign In to add comment