Bit more of a story would be:
Not all streams support peeking, seeking, etc... You can not always tell if
you are at the end of a stream. If you are using a FileStream then you
should use fileStream.Position == fileStream.Length to see if you are at the
end. If you are using a StreamReader you should get access to BaseStream,
make sure the CanSeek property returns true, and then check the Position
versus the Length. Simply doing a Peek can have negative side effects, such
as loading more data from disk since a StreamReader is buffered. If the
buffer is exhausted then you'll have to reload the buffer before it can
check the next char making Peek behave at an indeterminate speed.
Of course most of this really doesn't matter unless your coding some form of
high performance application.
--
Justin Rogers
DigiTec Web Consultants, LLC.
"Scott C. Wagner" <sw*******@SPAMseisint.com> wrote in message
news:O3**************@TK2MSFTNGP09.phx.gbl...
if (-1 == stream.Peek ())
{
// EOF
}
Scott Wagner
Seisint, Inc.
hu wrote:
How to figure out a stream is at the End-of-file? In C, just check the
FILE*equals to null. But how to do it in C#?
I know through StreamReader.ReadLine(), I can know when I reach the end
offile. However, this method is not suitable because I do not want to read
aline first... Any comments? Ideas?
Thanks,
HU