FileOutputStream fout = new FileOutputStream("D:\\Users\\src\\save");
ObjectOutputStream oos = new ObjectOutputStream(fout);
oos.writeObject(field); // вот здесь косяк, сохраняю весь класс
oos.close();
FileInputStream fin = new FileInputStream("D:\\Users\\src\\save");
ObjectInputStream ois = new ObjectInputStream(fin);
Object s = ois.readUnshared();
System.out.println(s);
ois.close();
public class Field implements Serializable {
List<GameObject> objects = new ArrayList<>();
public void addObject(GameObject o) {
objects.add(o);
}
List<String> list = new ArrayList<String>();
void moveAll() {
for (GameObject o : objects) {
Spot spot = o.move();
String s = o + " moved to " + spot;
list.add(s);
System.out.println(s);
}
}
}
List<String> list = new ArrayList<String>();
void moveAll() {
for (GameObject o : objects) {
Spot spot = o.move();
String s = o + " moved to " + spot;
list.add(s);
System.out.println(s);
}
}
��
public class Game implements Serializable {
public static void main(String[] args) throws InterruptedException, IOException, ClassNotFoundException, NotSerializableException {
Field field = new Field();
GameObject player = new Player();
field.addObject(player);
for (int i = 0; i < 10; i++) {
field.moveAll();
Thread.sleep(10);
}
FileOutputStream fout = new FileOutputStream("D:\\Users\\src\\save");
ObjectOutputStream oos = new ObjectOutputStream(fout);
oos.writeObject(field);
oos.close();
FileInputStream fin = new FileInputStream("D:\\Users\\src\\save");
ObjectInputStream ois = new ObjectInputStream(fin);
Object s = ois.readObject();
System.out.println(s);
ois.close();
}