我正在尝试将对象从ObjectInputStream
转换为我班级中已存在的对象:
//main class
Tester tester = new Tester();
tester.setHeight(50);
tester.setWidth(100);
/*FileOutputStream fs = new FileOutputStream("data.txt");
ObjectOutputStream os = new ObjectOutputStream(fs);
os.writeObject(tester);
os.close();*/
FileInputStream fis = new FileInputStream("data.txt");
ObjectInputStream ois = new ObjectInputStream(fis);
Tester x = (Tester) ois.readObject();
System.out.println(x.getHeight() + " " + x.getWidth());
我得到了:
java.io.InvalidClassException:Tester;本地类不兼容: stream classdesc serialVersionUID error。