问题描述
如何将DataInput转换为java中的DataInputStream?
我需要知道DataInput的大小。
由于流定义确实没有开始或结束,因此不知道有多少可用的万无一失的方法,你只需要从固定大小的块中读取流。这几乎听起来像你会更好地使用普通的旧.read()而不是readFully():
$ $ $ $ $ $ DataInputStream dis =新的DataInputStream(...);
byte [] buf = new byte [1024];
int lastRead = 0;
do {
lastRead = dis.read(buf);
//用'buf'在这里做一些事
} while(lastRead> 0);
How can I convert DataInput to DataInputStream in java?I need to know the size of the DataInput.
Since a stream, by definition, really has no begining or end and thus no fool proof way of knowing how much is available, you just have to read from the stream in fixed sized chunks. It almost sounds like you'd be better off with plain old .read() rather than readFully():
DataInputStream dis = new DataInputStream(...);
byte[] buf = new byte[1024];
int lastRead = 0;
do {
lastRead = dis.read(buf);
//do something with 'buf' here
} while (lastRead > 0);
这篇关于将DataInput转换为DataInputStream?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!