二进制阅读器ReadString的问题 [英] problem with binary reader ReadString
问题描述
您好,我在使用BinaryReader读取字符串方法时遇到问题.
我正在尝试从我的二进制读取器中读取3个字符串.但是,在C#中,ReadString方法抛出一个例外.
"{"无法读取到流的末尾."} System.Exception {System.IO.EndOfStreamException}"
我的代码如下
Hi
I am having a issue using the BinaryReader read string method.
I am attempting to read 3 strings from my binary reader. However in the C# the ReadString method throws an excpetion.
"{"Unable to read beyond the end of the stream."} System.Exception {System.IO.EndOfStreamException}"
my code is as follows
推荐答案
字体>
我的猜测是,在第一个示例中,您尝试从3个后续调用中读取3个字符串,并且不进行错误检查以查看是否存在更多字符,从而使您收到尝试读取字符串末尾的错误.
My guess is that in the first example, you are trying to read 3 strings from 3 subsequent call with no error checking to see if more characters exist, giving you the error that you are attempting to read past the end of the string.
在第二个效果很好的示例中,您将for字符串限制为i< count可能为0,如果缓冲区中没有要读取的字符,则会导致每个操作的读取都被跳过.
In the 2nd example which works fine, you are limiting the for strings to i < count which may be 0 which causes the read to be skipped over for each operation if there are no charactrs left in the buffer to read.
希望这会有所帮助.
这篇关于二进制阅读器ReadString的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!