将数据输入转换为数据输入流?
java中如何将DataInput转换为DataInputStream? 我需要知道数据输入的大小。
How can I convert DataInput to DataInputStream in java?
I need to know the size of the DataInput.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于根据定义,流实际上没有开始或结束,因此没有万无一失的方法来知道有多少可用,因此您只需以固定大小的块从流中读取。听起来你最好使用普通的旧 .read() 而不是 readFully():
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():
当您想知道要读取多少字节时,您会遇到困难。最简单的解决方案是将其转换为 ByteArrayInputStream 并使用它的 available() 方法来了解有多少字节可供读取。
以下示例对我有用
You'll encounter difficulty when you want know how many bytes to be read. Simplest solution is to cast it to a
ByteArrayInputStream
and use it's available() method to get to know how many bytes are available for reading.Following example worked for me