package cn.itcast_02;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
//对象的序列化与反序列化
public class ObjectOutputStreamDemo {
public static void main(String[] args) throws IOException, ClassNotFoundException {
//write();
read();
}
public static void write() throws IOException {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("oos.txt"));
Person p = new Person("林青霞",27);
oos.writeObject(p);
oos.close();
}
public static void read()throws IOException, ClassNotFoundException{
ObjectInputStream ois =new ObjectInputStream(new FileInputStream("oos.txt"));
Object obj=ois.readObject();
System.out.println(obj);
ois.close();
}
}
输出的结果是没有覆写toString方法的地址值
|
|