什么是DataOutputStream类和ObjectOutputStream的区别呢? [英] What's the difference between DataOutputStream and ObjectOutputStream?

查看:217
本文介绍了什么是DataOutputStream类和ObjectOutputStream的区别呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在学习如何用Java Socket编程。我见过的客户端/服务器应用程序的例子有一些使用 DataOutputStream类,和一些使用的ObjectOutputStream

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

什么是两者之间的区别是什么?

What's the difference between the two?

有没有性能上的差异?

推荐答案

的DataInput / OutputStream的执行通常更好,因为它更简单。它只能读/写primtive类型和字符串。

DataInput/OutputStream performs generally better because its much simpler. It can only read/write primtive types and Strings.

的ObjectInput / OutputStream中可以读/写任何对象类型是和原语。这是效率较低,但更容易使用,如果你想发送复杂的数据。

ObjectInput/OutputStream can read/write any object type was well as primitives. It is less efficient but much easier to use if you want to send complex data.

我会假设对象*流是最好的选择,直到你的知道的,它的性能是一个问题。

I would assume that the Object*Stream is the best choice until you know that its performance is an issue.

这篇关于什么是DataOutputStream类和ObjectOutputStream的区别呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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