import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; public class UpdatePath implements Serializable { private final String path; public UpdatePath(String path) { this.path = path; } public static void main(String[] arg) throws Exception { ByteArrayOutputStream byteoutStream = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(byteoutStream); out.writeObject(new UpdatePath("124kkkk")); out.flush(); final byte[] bytes = byteoutStream.toByteArray(); System.out.println(bytes); for (int i = 0; i < bytes.length; i++) { System.out.print(bytes[i]); System.out.print(" "); } out.close(); ObjectInputStream messageReader = new ObjectInputStream( new ByteArrayInputStream(bytes)); UpdatePath path = (UpdatePath) messageReader.readObject(); System.out.println("============================="); System.out.println(path.path); messageReader.close(); } }
java对象序列化序列化例子
最新推荐文章于 2021-02-28 13:36:53 发布