Binary data reading
Hi!
I am having problem reading binary ( in fact any file) file using the following code:
Here is the code:
FileStream fs=new FileStream("C:\abc.dat", System.IO.FileMode.Open, System.IO.FileAccess.Read);
byte[] b=new byte[fs.Length - 1];
int fslen=(int) fs.Length;
fs.Read(b,0,fslen);
I am getting error:
Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.
Same code works fine with vb:
Dim f As System.IO.File
Dim fs As System.IO.FileStream
fs = f.Open("C:\abc.dat ", IO.FileMode.Open, IO.FileAccess.Read)
Dim b(fs.Length - 1) As Byte
fs.Read(b, 0, fs.Length)
any idea? Thanks in Advance.
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

AdministratorRank #675 · 3.6K reputationPosted Mar 14, 2003, 6:26 AM EST
AdministratorRank #675 · 3.6K reputationPosted Mar 14, 2003, 9:09 AM EST