1:object ->byte[]
Object ob ;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(ob);
oos.flush();
byte [] bytes = bos.toByteArray ();
oos.close();
bos.close();
2:byte[] ->Object
byte [] bytes;
ByteArrayInputStream bis =newByteArrayInputStream (bytes);
ObjectInputStream ois =newObjectInputStream (bis);
Object obj = ois.readObject();
ois.close();
bis.close();
网友评论