对象与字节数组之间的转换
将对象转换成字节数组
public byte[] object2Byte(Object obj)throws IOException{
ByteOutputStream bos = new ByteOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(obj);
return bos.toByteArray();
}
将字节数组转换成对象
public Object byte2Object(byte[] bytes) throws IOException, ClassNotFoundException{
ByteInputStream bis = new ByteInputStream();
ObjectInputStream ois = new ObjectInputStream(bis);
return (Object)ois.readObject();
}