From 07b55675f3f7282e8a4dbbd9c6dc661ba08e6cd6 Mon Sep 17 00:00:00 2001 From: bingor Date: Wed, 19 Oct 2022 09:33:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9D=A6=E5=85=8B=E5=A4=A7=E6=88=98=EF=BC=88?= =?UTF-8?q?=E4=B8=80=E6=9C=9F=EF=BC=89-=E8=AE=BE=E8=AE=A1=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F-=E5=A4=87=E5=BF=98=E5=BD=95=E6=A8=A1=E5=BC=8F1.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/msb/model/GameModel.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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(); + } } }