参考:http://tristan1.iteye.com/blo...
public void testDeserialize() throws IOException, ClassNotFoundException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); BigInteger bi = new BigInteger("0"); oos.writeObject(bi); byte[] str = baos.toByteArray(); ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(new ByteArrayInputStream(str))); Object obj = ois.readObject(); assertNotNull(obj); assertEquals(obj.getClass().getName(),"java.math.BigInteger"); assertEquals(((BigInteger)obj).intValue(), 0); }
关键处理
byte[] str = baos.toByteArray();
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号