Administrator

Administrator

  • Tech Writer
  • 2.2k
  • 1.5m

Binary data reading

Mar 14 2003 10:46 AM
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.

Answers (2)