日期:2014-05-18 浏览次数:20729 次
class Person implements Serializable{
private static final long serialVersionUID = 4212275679707232020L;
private String name,address;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
public static void main(String[] args) throws Exception {
serializableObject();
//如果这里是通过socket的OutputStream输出到1个ServerSocket,那么该如何反序列化呢?
//Server端并没有我这个entity的类型,是通过反射动态构造出这样1个类型吗,如果是,怎么做呢?
}
public static void serializableObject() throws Exception{
File file = new File("F:"+File.separator+"person.ini");
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
Person per = new Person();
per.setAddress("深圳");
per.setName("Sean.zhang");
oos.writeObject(per);
oos.close();
}