diff --git a/src/main/java/com/msb/model/GameModel.java b/src/main/java/com/msb/model/GameModel.java index 13cb17c..ae11f28 100644 --- a/src/main/java/com/msb/model/GameModel.java +++ b/src/main/java/com/msb/model/GameModel.java @@ -130,12 +130,19 @@ public class GameModel { public void save() { File file = new File("F:\\bingor\\temp\\tank.data"); + ObjectOutputStream oos = null; try { - ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file)); + oos = new ObjectOutputStream(new FileOutputStream(file)); oos.writeObject(myTank); oos.writeObject(gameObjects); } catch (IOException e) { e.printStackTrace(); + } finally { + try { + oos.close(); + } catch (IOException e) { + e.printStackTrace(); + } } } @@ -148,6 +155,12 @@ public class GameModel { gameObjects = (List) ois.readObject(); } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); + } finally { + try { + ois.close(); + } catch (IOException e) { + e.printStackTrace(); + } } }