java序列化异常_Java|序列化异常StreamCorruptedException的解决方法
參考: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|序列化异常StreamCorruptedException的解决方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android java和c混合编程_C
- 下一篇: linux mysql 5.7 双机热备