![](/img/trans.png)
[英]If -1 is the standard EOF byte, why does DataInputStream do this?
[英]Why do I get EOF exception while reading a datainputstream in java?
这是我要阅读的内容:
FileInputStream fis=new FileInputStream("count.txt");
BufferedInputStream bis=new BufferedInputStream(fis);
DataInputStream dis=new DataInputStream(bis);
while(dis.read()!=-1)
{
orderCount=dis.readInt();
newOrderCount=dis.readInt();
}
Count.txt具有数据,例如0 0 0 0 0 0 0 0 1,但是由于某种原因我收到了EOF异常,请帮助!
EOFException
意味着您试图读取流的末尾,这可能是因为您正在读取一个字节然后将其丢弃,这已经是一个错误,因为它使您与发送方不同步,这可能是发生的。 将循环测试更改为while (true)
,捕获EOFException
,并在获取测试时关闭套接字并退出循环。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.