Help with streamreader

  • Thread starter Thread starter Mike R
  • Start date Start date
M

Mike R

Hi All,

I'm trying to read a file that has the following format, its a variable
record file, the first byte determines how to process the rest.

byte 1 = either 0,1,2,3
4 bytes = size of the file
other bytes = lots of stuff

I'm bascially stuck on getting the 4 bytes into an int32!

dim myfile as new fileinfo("c:\test.dat")

dim myreader as streamreader

myreader=myfile.opentext

while myreader.peek <>-1

' read the first byte
rType = oread.read()

dim chararray(1) as char

oread.readblock(chararray,0,2)

....This is where i'm stuck - how to get the chararray into an int32. Or am
I approaching this the wrong way

any help my appreciated.

Thanks
Mike
 
Mike R said:
I'm trying to read a file that has the following format, its a variable
record file, the first byte determines how to process the rest.

byte 1 = either 0,1,2,3
4 bytes = size of the file
other bytes = lots of stuff

Use 'BinaryReader' instead of 'StreamReader'.
 
Mike R said:
Hi All,

I'm trying to read a file that has the following format, its a
variable record file, the first byte determines how to process the
rest.

byte 1 = either 0,1,2,3
4 bytes = size of the file
other bytes = lots of stuff

I'm bascially stuck on getting the 4 bytes into an int32!

dim myfile as new fileinfo("c:\test.dat")

dim myreader as streamreader

myreader=myfile.opentext


You could use the Streamreader's Read function to read an Int32 value.
Though, if I wanted to read binary data, I wouldn't use "Opentext" because
it's there for plain text files. Instead, open a FileStream, then use a
BinaryReader to read the binary data (methods ReadByte, ReadInt32, ...). You
can still use a Streamreder to read Chars from the file.


Armin
 
Armin Zingler said:
You could use the Streamreader's Read function to read an Int32 value.
Though, if I wanted to read binary data, I wouldn't use "Opentext" because
it's there for plain text files. Instead, open a FileStream, then use a
BinaryReader to read the binary data (methods ReadByte, ReadInt32, ...).
You can still use a Streamreder to read Chars from the file.


Armin


Thanks for this, Its is now working.

Kind Regards

Mike
 
Back
Top