C#-流/文件流EOF [英] C# - Stream/FileStream EOF
问题描述
有人知道文件的结尾吗?
我正在使用BinaryReader并尝试了PeekChar-但它引发了异常。还有其他建议吗?
Is anyone familiar with a way to find out you're at the end of the file? I'm using BinaryReader and tried PeekChar - but it throws an exception. Any other suggestions?
谢谢。
推荐答案
从 Stream
,如果您 Read(缓冲区,偏移量,计数)
,则会得到非正结果,而如果您 Peek()
您会得到否定的结果。
From a Stream
, if you Read(buffer, offset, count)
you'll get a non-positive result, and if you Peek()
you'll get a negative result.
带有 BinaryReader
,文档建议 PeekChar()
应该返回负值:
With a BinaryReader
, the documentation suggests that PeekChar()
should return negative:
返回值
类型:System.Int32
下一个可用字符;如果没有更多可用字符或流不支持查找,则返回-1。
Return Value
Type: System.Int32 The next available character, or -1 if no more characters are available or the stream does not support seeking.
您确定这不是腐败流吗?即剩余的数据无法根据给定的编码形成完整的 char
?
are you sure this isn't a corrupt stream? i.e. the remaining data cannot form a complete char
from the given encoding?
这篇关于C#-流/文件流EOF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!