checking for EOF

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
 
A

Armin Zingler

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
 
C

Cerebrus

Hi,

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

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

Regards,

Cerebrus.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top