首页  >  文章  >  类库下载  >  Java|序列化异常StreamCorruptedException的解决方法

Java|序列化异常StreamCorruptedException的解决方法

高洛峰
高洛峰原创
2016-10-15 16:33:112069浏览

参考: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();


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn