Java socket: dataoutputstream or OutputStream?

I'm still a relatively new socket, and I haven't seen any information about this topic

To write to a connected socket, you can use

socket.getOutputStream().write

Or create a new dataoutputstream from the socket OutputStream and write it

>Using dataoutputstream or OutputStream is considered a "good habit"? Most of the examples I found on the Internet using dataoutputstream (sending strings, such as two-way chat). > What are the advantages or disadvantages of using dataoutputstream on OutputStream? > In these two cases, for example, when sending files, is the performance different?

Solution

Dataoutputstream ensures that data is formatted in a platform - independent manner This is the greatest advantage It ensures that the other party's party can be read There is no significant performance difference between the two

You can only use OutputStream when transferring raw binary data

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>