Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check for end of file in FileStream while reading data

Status
Not open for further replies.

StellaIndigo

IS-IT--Management
Sep 19, 2002
118
GB
Hi

I need to read blocks of a binary data file with Visual Studio 2005.

I can't seem to find a way of checking for Eof (End of file)
looping around a FileStream ReadBytes operation. I can't find Eof values in the FileStream class and I tried to catch the possible error during ReadBytes but no error is thrown.

Code:
Dim arrDataBlock(128) As Byte
Dim fs As FileStream = New FileStream("c:\temp\file.dat", FileMode.OpenOrCreate)
Dim rs As System.IO.BinaryReader = New System.IO.BinaryReader(fs)

{ LOOP START here to read blocks until Eof }

arrDataBlock = rs.ReadBytes(128)
... my code to process the data block

{ LOOP ENDS }
fs.Close()


Can anyone help?




Regards
Stella

There are 10 types of people in the world. Those that understand binary and those that don't.
 
Peek method.

"The current position of the StreamReader object is not changed by Peek. The returned value is -1 if no more characters are currently available."

C
 
works a treat peeking the next char.

many thanks.

Regards
Stella

There are 10 types of people in the world. Those that understand binary and those that don't.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top