Java sockets: DataOutputStream or OutputStream?

后端 未结 3 2136
慢半拍i
慢半拍i 2021-02-07 08:11

I\'m still relatively new to sockets, and I haven\'t seen any information regarding this subject.

To write to a connected socket, you can either use

sock         


        
3条回答
  •  离开以前
    2021-02-07 08:26

    DataOutputStream makes sure the data is formatted in a platform independent way. This is the big benefit. It makes sure the party on the other side will be able to read it. There is no significant performance difference between both.

    You should use OutputStream only if you transfer raw binary data.

提交回复
热议问题