之间的DataInputStream / DataOutputStream类与类功放差异;的InputStream / OutputStream的类 [英] Difference Between DataInputStream/DataOutputStream Class & InputStream/OutputStream Class

查看:151
本文介绍了之间的DataInputStream / DataOutputStream类与类功放差异;的InputStream / OutputStream的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我在的Java ME使用的HttpConnection 安卓黑莓,我使用的DataInputStream / DataOutputStream类类阅读和放大器;写DATAS通过远程服务器。不过也有其他类如的InputStream / 的OutputStream 它可以用于同样的目的。我看到关于的InputStream / 的OutputStream 的HttpConnection 问题。所以我想从专家们知道,什么是这两者之间的区别是什么?

Whenever I use HttpConnection Class in Java ME, Android or in BlackBerry, I uses DataInputStream/DataOutputStream class for reading & writing datas over remote server. However there are other class like InputStream/OutputStream which can be use for same purpose. I saw Question regarding InputStream/OutputStream class with HttpConnection. So I would like to know from experts that what are the differences between these two ?

推荐答案

的DataInputStream / DataOutputStream类ISA的InputStream / OutputStream中。 InputStream和OutputStream是最通用的IO流可以使用,他们是在Java中所​​有流的基类。您可以阅读与他们编写原始字节。写入的DataInputStream格式的二进制数据。而不是只是简单的格式化字节就可以读取的字节,整型,双精度浮点型,短,UTF-8字符串,并且数据的混合物。而同样也只是它写这些更高级别的数据类型可以说为DataOutputStream类。一个DataInputStream / DataOutputStream类引用了一个InputStream / OutputStream中,它读取原始字节和跨$ P $点那些previously提到的数据类型,这些字节。

DataInputStream/DataOutputStream isa InputStream/Outputstream. InputStream and OutputStream are the most generic IO streams you can use and they are the base class of all streams in Java. You can read and write raw bytes only with them. DataInputStream writes formatted binary data. Instead of just simple unformatted bytes you can read Bytes, Integer, Double, Float, Short, UTF-8 strings, and any mixture of that data. And same can be said for DataOutputStream except that it writes these higher level data types. A DataInputStream/DataOutputStream has a reference to an InputStream/OutputStream which it reads the raw bytes and interprets those bytes as those previously mentioned data types.

虽然从阅读的DataInputStream串是不是一个好主意,因为它使对底层InputStream的字符编码​​不变的假设。相反,它是更好地使用阅读器将正确应用字符编码的基础字节流中读取数据。这就是为什么的DataInputStream / DataOutputStream类是有限。通常情况下最好是因为它是最容易使服务器和客户端上如何分析数据一致进程之间的交易文本数据。交易二进制有很多位操作,有发生,以确保每道工序都讲同一种语言的。它很容易,如果你有使用的DataInputStream / DataOutputStream类两个Java程序,但如果你想添加一个新的客户端,它不是Java,你就会有一个更难的时间重新使用。不是不可能,只是更难。

Although reading strings from the DataInputStream isn't a good idea because it makes unchangeable assumptions about the character encoding of the underlying InputStream. Instead it's better to use a Reader which will properly apply character encodings to the underlying byte stream to read data. That's why DataInputStream/DataOutputStream is of limited use. Typically it's better to trade textual data between processes because it's easiest to make a server and client agree on how to parse the data. Trading binary has lots of bit twiddling that has to occur to make sure each process is talking the same language. Its easy if you have two Java processes using DataInputStream/DataOutputStream, but if you ever want to add a new client that isn't Java you'll have a harder time reusing it. Not impossible, but just harder.

这篇关于之间的DataInputStream / DataOutputStream类与类功放差异;的InputStream / OutputStream的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆