问答详情
源自:6-1 序列化基本操作

为什么输出的是对象的存储地址???

http://img.mukewang.com/58c1404100014a2203220244.jpg

public class ObjectSeriaDemo1 {

public static void main(String[] args) throws Exception{

String file = "demo/obj.dat";

//1.对象的序列化

/*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();

}


}


提问者:Flynee 2017-03-09 19:45

个回答

  • 卖底环的超人
    2017-03-09 21:54:08

    因为在Student类中,你没有创建toString()方法