Java – difference between datainputstream / dataoutputstream class and InputStream / OutputStream class

Whenever I use HTTPCONNECTION class in java me, Android or blackberry, I will use datainputstream / dataoutputstream class to read and write data on the remote server. However, there are other classes, such as InputStream / OutputStream, It can be used for the same purpose. I see the problem about the InputStream / OutputStream class of HTTPCONNECTION. So I want to know from experts what is the difference between the two?

resolvent:

Datainputstream / dataoutputstream is an InputStream / OutputStream. InputStream and OutputStream are the most common IO streams you can use. They are the base classes of all streams in Java. You can only use them to read and write raw bytes. Datainputstream writes formatted binary data. You can read bytes, integer, double, float, short, UTF-8 string and any mixture of this data, not just simple unformatted bytes. This can also be said for dataoutputstream, except that it writes these higher-level data types. Datainputstream / dataoutputstream has a reference to InputStream / OutputStream, which reads the original bytes and interprets these bytes as the data types mentioned above

Although reading a string from a datainputstream is not a good idea because it makes an unalterable assumption about the character encoding of the underlying InputStream. On the contrary, it is best to use a reader that can correctly apply the character encoding to the underlying byte stream to read data. This is why the use of datainputstream / dataoutputstream is limited. Usually, It's best to exchange text data between processes, because the simplest way is to let the server and client agree on how to parse the data. Transaction binaries are a lot of trouble, and you must ensure that each process uses the same language. If you have two Java processes using datainputstream / dataoutputstream, it's easy, But if you want to add a new client that is not Java, it will be difficult to reuse it. Not impossible, but more difficult

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
分享
二维码
< <上一篇
下一篇>>