J2SE中的序列化的认识
添加时间: 2006-2-18 5:21:42 作者: JSP教程 阅读次数:48 来源: http://www.d9soft.com
in = new FileInputStream("5.txt");
oin = new ObjectInputStream(in);
Serial serial2 = Serial.deserialize(oin);//反序列化
System.out.println(serial2);//打印结果
} catch (Exception ex){
ex.printStackTrace();
} finally{
try {
if (in != null) {
in.close();
}
if (oin != null) {
oin.close();
}
if (out != null) {
out.close();
}
if (oout != null) {
oout.close();
}
} catch (IOException ex1) {
ex1.printStackTrace();
}
}
}
/**
* deserialize
*/
public static Serial deserialize(ObjectInputStream oin) throws Exception{
Serial s=(Serial)oin.readObject();
return s;
}
public String toString() {
return "DATA: "+company_id+" "+company_addr+" "+company_flag;
}
/**
* serialize
*/
public void serialize(ObjectOutputStream oout) throws Exception{
oout.writeObject(this);
}
}
运行结果:
DATA: 752 dayer street #5 building 02-287 false
正确打印了结果。
上一篇文章: JSP连接各类数据库大全 下一篇文章: JSP程序员成长之路

