坦克大战(一期)-设计模式-备忘录模式1.1

DesignPatterns
bingor 2 years ago
parent db587a297d
commit 07b55675f3

@ -130,12 +130,19 @@ public class GameModel {
public void save() { public void save() {
File file = new File("F:\\bingor\\temp\\tank.data"); File file = new File("F:\\bingor\\temp\\tank.data");
ObjectOutputStream oos = null;
try { try {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file)); oos = new ObjectOutputStream(new FileOutputStream(file));
oos.writeObject(myTank); oos.writeObject(myTank);
oos.writeObject(gameObjects); oos.writeObject(gameObjects);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} finally {
try {
oos.close();
} catch (IOException e) {
e.printStackTrace();
}
} }
} }
@ -148,6 +155,12 @@ public class GameModel {
gameObjects = (List<GameObject>) ois.readObject(); gameObjects = (List<GameObject>) ois.readObject();
} catch (IOException | ClassNotFoundException e) { } catch (IOException | ClassNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} finally {
try {
ois.close();
} catch (IOException e) {
e.printStackTrace();
}
} }
} }

Loading…
Cancel
Save