Home All Groups Group Topic Archive Search About
Author
16 Mar 2006 3:43 PM
Dave Cullen
How does one check for end-of-file while using the Streamreader class
methods?

File opened like so...

inputstream = File.OpenRead(Infile)
Dim SrRead As StreamReader = New StreamReader(inputstream, _
                System.Text.Encoding.ASCII)

I intend to do-while not EOF using SrRead.Readline and I can't figure
out what to use for the EOF check.

Thanks

Author
16 Mar 2006 4:02 PM
Armin Zingler
Show quote Hide quote
"Dave Cullen" <nospam@mail.com> schrieb
> How does one check for end-of-file while using the Streamreader
> class methods?
>
> File opened like so...
>
> inputstream = File.OpenRead(Infile)
> Dim SrRead As StreamReader = New StreamReader(inputstream, _
>        System.Text.Encoding.ASCII)
>
> I intend to do-while not EOF using SrRead.Readline and I can't
> figure out what to use for the EOF check.
>
> Thanks

According to the documentation, ReadLine returns Nothing if the end of the
stream is reached.


Armin
Author
16 Mar 2006 4:27 PM
Herfried K. Wagner [MVP]
"Dave Cullen" <nospam@mail.com> schrieb:
> I intend to do-while not EOF using SrRead.Readline and I can't figure
> out what to use for the EOF check.

Reading a text file line-by-line or blockwise with a progress indicator
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=readfile&lang=en>

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
17 Mar 2006 8:08 AM
Cerebrus
Hi,

I think StreamReader.Peek() replicates that functionality. Just use :

While (SrRead.Peek() > -1)
:
:
End While

Regards,

Cerebrus.