1.对象可以通过实现:Serializable 或者 ExternalSerializable,或者功能更加强大,但实现也复杂。 2.不进行序列化(与本地有关,为实现Serialixzable的对象引用)的数据域使用 transient,同时static数据域也不可序列化;这些数据在对象被读入时使用默认值赋值。 3.serialVersionUID 为类的指纹,通过HAS计算所得,类改变就会改变。
output = new FileOutputStream(new File("D:\\test\\abc.dat"));
ObjectOutputStream out=new ObjectOutputStream(output);
Person p=new Person("wxz",20);
p.setTag("handsboy");
out.writeObject(p);
FileInputStream fileIn=null;
ObjectInputStream input=null;
try {
fileIn = new FileInputStream(new File("D:\\\\test\\\\abc.dat"));
input=new ObjectInputStream(fileIn);
Person p=(Person)input.readObject();