From 19134408a889f729f0fa69bf5f31d5d8f41f46a3 Mon Sep 17 00:00:00 2001 From: Vikramb987 <47336882+Vikramb987@users.noreply.github.com> Date: Mon, 25 Mar 2019 13:18:16 -0600 Subject: [PATCH] Update FileSaving.java changes to how we deal with saving when it comes to the terminal --- src/FileSaving.java | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/FileSaving.java b/src/FileSaving.java index b5143de..60055f8 100644 --- a/src/FileSaving.java +++ b/src/FileSaving.java @@ -13,6 +13,7 @@ public class FileSaving extends Player implements Serializable { * @return player */ public Player loadFile() { + try { InputStream in = new FileInputStream(new File("src/saves/playerSave.txt")); ObjectInputStream inObject = new ObjectInputStream(in); @@ -22,7 +23,17 @@ public class FileSaving extends Player implements Serializable { return player; } catch (Exception e) { - return null; + try { + InputStream in = new FileInputStream(new File("saves/playerSave.txt")); + ObjectInputStream inObject = new ObjectInputStream(in); + Player player = (Player) inObject.readObject(); + in.close(); + inObject.close(); + return player; + } + catch(Exception e2){ + return null; + } } } @@ -39,7 +50,18 @@ public class FileSaving extends Player implements Serializable { return true; } catch (Exception e) { - return false; + try { + FileOutputStream out = new FileOutputStream(new File("saves/playerSave.txt")); + ObjectOutputStream outObject = new ObjectOutputStream(out); + outObject.writeObject(player); + + out.close(); + outObject.close(); + return true; + } + catch(Exception e2){ + return false; + } } }