序列化在java中就是把数据变为byte[] ,以便传输数据或保存数据;反序列化是将byte[]转变为java数据;✨
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);
}
}