2
Answers

Binary data reading

Ask a question
Administrator

Administrator

21y
1.4k
1
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)