本文介绍了DataInputStream.read()vs DataInputStream.readFully()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个简单的TCP / IP套接字应用程序

Im making a simple TCP/IP Socket app

这样做有什么不同:

DataInputStream in = new DataInputStream(clientSocket.getInputStream());

byte[] buffer = new byte[100];
in.readFully(buffer);

与此相反:

DataInputStream in = new DataInputStream(clientSocket.getInputStream());

byte[] buffer = new byte[100];
in.read(buffer);

我查看了文档,他们有完全相同的描述。 和
那么我可以假设它是一样的吗?

I had a look at the documentation, they have the same exact description. readFully() and read()So can I assume its the same thing?

推荐答案

的Javadoc> DataInput.readFully(byte [] b)状态:

的Javadoc> DataInputStream.read(byte [] b)状态:

基本上, readFully()将读取完全 b.length 字节,而 read()将读取最多 b.length ,或许更少,无论从输入流。

Basically, readFully() will read exactly b.length bytes, whereas read() will read up to b.length, maybe less, whatever is available from the input stream.

这篇关于DataInputStream.read()vs DataInputStream.readFully()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 06:57