package com.IOUtil.io;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public class ObjectSeriaDemo01 {
public static void main(String[] args) throws IOException, ClassNotFoundException {
/*
//对象的序列化
String file = "demo\\obj.dat";
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
Student stu = new Student("012", "王栋祥", 22);
oos.writeObject(stu);
*/
//对象的反序列化
String file = "demo\\obj.dat";
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
//ois.readObject();
System.out.println(ois.readObject());
}
}
我自己创建了一个学生类,然后用你的代码就是不行,必须要强转
不可能吧,你在自己试试看,你试一下强转后的结果,在试一下没强转的,强转的对象是你的学生对象