62,614
社区成员
发帖
与我相关
我的任务
分享
public class Demo {
public static void main(String[] args) throws IOException, Exception {
readObj();
//反序列化
public static void readObj() throws ClassNotFoundException, IOException {
File file = new File("D:\\userData.txt");
FileInputStream fileInputStream = new FileInputStream(file);
//建立对象的输入流对象
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
//读取对象信息
User user = (User) objectInputStream.readObject(); //执行到这句话老是报错 Exception in thread "main" java.io.InvalidClassException: ObjectStream.User; local class incompatible: stream classdesc serialVersionUID = -1824221932951318999, local class serialVersionUID = 839438564830603174
System.out.println("对象的信息:"+ user);
}
}