首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

(大牛进)关于序列化和反射的有关问题

2013-07-11 
(大牛进)关于序列化和反射的问题1个entity:class Person implements Serializable{private static final l

(大牛进)关于序列化和反射的问题
1个entity:


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;
}

}


question:

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();
}

[解决办法]
服务端必须加载了Person类的CLASS,不然会抛出ClassNotFoundException.

热点排行