对象序列化

来源:互联网 发布:java session取不到值 编辑:程序博客网 时间:2024/05/24 05:08
//定义一个字节数组输出流ByteArrayOutputStream os = new ByteArrayOutputStream();//对象输出流ObjectOutputStream out = new ObjectOutputStream(os);//将对象写入到字节数组输出,进行序列化out.writeObject(zhangcan);byte[] zhangsanByte = os.toByteArray();//字节数组输入流ByteArrayInputStream is = new ByteArrayInputStream(zhangsanByte);//只想反序列化,从流中读取对象ObjectInputStream in = new ObjectInputStream(is);Person person = (Person)in.readObject();
//使用Hessian进行序列化ByteOutputStream os = new ByteOutputStream();//Hessian 的序列化HessianOutput ho = new HessianOutput(os);ho.writeObject(zhangsan);byte[] zhangsanByte = os.toByteArray();ByteArrayInputStream is = new ByteArrayInputStream();//Hessian的反序列化读取对象HessianInput hi = new HessianInput();
Person person = (Person)in.readObject();


0 0
原创粉丝点击