User user=new User();
user.setId("bonnie");
user.setAge("10");
//Object转byte[]
ByteArrayOutputStream byteArrayOutputStream =new ByteArrayOutputStream();
ObjectOutputStream objectOutputStream=new ObjectOutputStream(byteArrayOutputStream);
objectOutputStream.writeObject(user);
byte[] bytes=byteArrayOutputStream.toByteArray();
//byte[]转Object
ByteArrayInputStream byteArrayInputStream=new ByteArrayInputStream(bytes);
ObjectInputStream objectInputStream=new ObjectInputStream(byteArrayInputStream);
User user1=(User)objectInputStream.readObject();
System.out.println(user1);