序列化在java中就是把數(shù)據(jù)變?yōu)閎yte[] ,以便傳輸數(shù)據(jù)或保存數(shù)據(jù)胡桨;反序列化是將byte[]轉(zhuǎn)變?yōu)閖ava數(shù)據(jù)官帘;?
public static void main(String[] args) {
try(ByteArrayOutputStream buffer=new ByteArrayOutputStream(); ObjectOutputStream output=new ObjectOutputStream(buffer);
) {
output.writeInt(12);
output.writeObject(Integer.valueOf(100));
ByteArrayInputStream buffer2=new ByteArrayInputStream(buffer.toByteArray());
ObjectInputStream input=new ObjectInputStream(buffer2);
System.out.println(input.readInt());
System.out.println(input.readObject());
} catch (IOException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}