[英]Why do I get EOF exception while reading a datainputstream in java?
Here is what I am trying to read : 这是我要阅读的内容:
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 has data such as 0 0 0 0 0 0 0 1, but for some reason i get an EOF exception,please help! Count.txt具有数据,例如0 0 0 0 0 0 0 0 1,但是由于某种原因我收到了EOF异常,请帮助!
EOFException
means you tried to read past the end of the stream, which probably happened because you are reading a byte and then throwing it away, which is already a bug, as it puts you out of sync with the sender. EOFException
意味着您试图读取流的末尾,这可能是因为您正在读取一个字节然后将其丢弃,这已经是一个错误,因为它使您与发送方不同步,这可能是发生的。 Change the loop test to while (true)
, catch EOFException
, and, when you get it, close the socket and break out of the loop. 将循环测试更改为
while (true)
,捕获EOFException
,并在获取测试时关闭套接字并退出循环。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.