為什么輸出的是對(duì)象的存儲(chǔ)地址???
public class ObjectSeriaDemo1 {
public static void main(String[] args) throws Exception{
String file = "demo/obj.dat";
//1.對(duì)象的序列化
/*ObjectOutputStream oos = new ObjectOutputStream(
new FileOutputStream(file));
Student stu = new Student("10001", "張三", 20);
oos.writeObject(stu);
oos.flush();
oos.close();*/
ObjectInputStream ois = new ObjectInputStream(
new FileInputStream(file));
Student stu = (Student)ois.readObject();
System.out.println(stu);
ois.close();
}
}
2017-03-09
因?yàn)樵赟tudent類中,你沒有創(chuàng)建toString()方法