[英]Deserializing an Object that has been serialized using ObjectOutputStream's writeObject method
If you serialize an Object using ObjectOutputStream's writeObject method, is the only way to deserialize it through ObjectInputStream's readObject method? 如果使用ObjectOutputStream的writeObject方法序列化对象,那么通过ObjectInputStream的readObject方法反序列化对象的唯一方法是吗? Can you call ObjectInputStream's other read methods? 您可以调用ObjectInputStream的其他读取方法吗?
Items in object streams are tagged. 对象流中的项目被标记。 If you try to use the wrong readXXX()
primitive to read them you will get an EOFException
. 如果尝试使用错误的readXXX()
原语读取它们,则将得到EOFException
。 The only methods you can use to read a written object are readObject()
and readUnshared().
只能使用readObject()
和readUnshared().
来读取书面对象readUnshared().
You can always read the raw bytes with the read()
methods of course, but you'll probably make it impossible to use any of the readXXX()
methods afterwards, by moving to an arbitrary position in the stream. 当然,您始终可以使用read()
方法读取原始字节,但是之后可能会无法移动到流中的任意位置,从而无法使用任何readXXX()
方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.