Java 序列化

		TestSrl t = new TestSrl();
		System.out.println(t);
		ByteArrayOutputStream bs = new ByteArrayOutputStream();
		ObjectOutputStream os = new ObjectOutputStream(bs);
		os.writeObject(t);
		os.writeObject(t);

		ObjectInputStream in1 = new ObjectInputStream(new ByteArrayInputStream(
				bs.toByteArray())), in2 = new ObjectInputStream(
				new ByteArrayInputStream(bs.toByteArray()));
		TestSrl t1 = (TestSrl) in1.readObject(), t3 = (TestSrl) in1
				.readObject();
		System.out.println(t1);
		System.out.println(t3);

		TestSrl t2 = (TestSrl) in2.readObject();
		System.out.println(t2);

 运行结果

TestSrl [TestSrl@1fa1bb6]
TestSrl [TestSrl@1bbf1ca]
TestSrl [TestSrl@1bbf1ca]
TestSrl [TestSrl@1ff0dde]

你可能感兴趣的:(java)