JAVA 序列化对象 ObjectInputStream先用就出现异常?
1个回答
展开全部
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(buffer);
out.writeObject(null);
out.writeObject(1);
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
System.out.println(in.readObject());
System.out.println(in.readObject());
} catch (Exception e) {
e.printStackTrace();
}
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(buffer);
out.writeObject(null);
out.writeObject(1);
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
System.out.println(in.readObject());
System.out.println(in.readObject());
} catch (Exception e) {
e.printStackTrace();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询