[color=red]主要的类是ObjectOutputStream ObjectInputStream 和 ByteArrayOutputStream ByteArrayInputStream [/color]
对象转Byte[]
Byte[]转对象
对象转Byte[]
ObjectOutputStream oos = null;
ByteArrayOutputStream byteOut = null;
try {
byteOut = new ByteArrayOutputStream();
oos = new ObjectOutputStream(byteOut);
oos.writeObject(obj);
byte[] bytes = byteOut.toByteArray();
} catch (Exception e) {
}
Byte[]转对象
ByteArrayInputStream in = null;
try {
in = new ByteArrayInputStream(bytes);
ObjectInputStream objIn = new ObjectInputStream(in);
Object obj = objIn.readObject();
} catch (Exception e) {
}