What's the difference between DataOutputStream and ObjectOutputStream?

前端 未结 4 776
梦如初夏
梦如初夏 2020-12-15 05:49

I\'m learning about socket programming in Java. I\'ve seen client/server app examples with some using DataOutputStream, and some using ObjectOutputStream

4条回答
  •  不知归路
    2020-12-15 06:21

    Only objects that implement the java.io.Serializable interface can be written to streams using ObjectOutputStream.Primitive data types can also be written to the stream using the appropriate methods from DataOutput. Strings can also be written using the writeUTF method. But DataInputStream on the other hand lets an application write primitive Java data types to an output stream in a portable way.

    Object OutputStream

    Data Input Stream

提交回复
热议问题