简体   繁体   English

反序列化使用ObjectOutputStream的writeObject方法序列化的对象

[英]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.

相关问题 Java 的 ObjectOutputStream 的 writeObject() 方法如何处理数组? - How does Java's ObjectOutputStream's writeObject() method work for array? ObjectOutputStream的对象如何调用Serializable对象的私有writeObject方法 - How private writeObject method of Serializable object called by object of ObjectOutputStream ObjectOutputStream方法writeObject挂在android上 - ObjectOutputStream method writeObject hangs on android ObjectOutputStream的writeObject方法使用什么字符编码? - What character encoding does ObjectOutputStream 's writeObject method use? ObjectOutputStream .writeObject - ObjectOutputStream .writeObject 返回空文件的ObjectOutputStream writeObject()方法 - ObjectOutputStream writeObject() method returning empty file java.io.NotSerializableException :: ObjectOutputStream:writeObject方法 - java.io.NotSerializableException:: ObjectOutputStream: writeObject method 我应该同步 ObjectOutputStream.writeObject(Object) 吗? - Should I synchronize ObjectOutputStream.writeObject(Object)? 使用ObjectOutputStream.writeObject()无法进行数据传输 - data transfer not working using ObjectOutputStream.writeObject() 通过ObjectOutputStream的writeObject方法进行Java ArrayList序列化将不起作用 - Java ArrayList serialization through ObjectOutputStream's writeObject method won't work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM