checking for EOF

  • Thread starter Thread starter Dave Cullen
  • Start date Start date
D

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
 
Dave Cullen said:
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
 
Hi,

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

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

Regards,

Cerebrus.
 
Back
Top