I have to open a log file created by c++, which is 4G in size.
I want to read it from C#, but FileStream.Read uses int as offset, that means I can not read bigger than 2G. I believe C# should have a solution for it.

How can I read a binary file which is bigger than 2G?

I really appreciate your help.


The FileStream.Read method uses the offset to define a position in byte array, not in the file, file position is 0, and increases each time a byte is read from the file. Or you can use FileStream.Seek to set the position, which uses type long.

Type long is equivalent to System.Int64 and goes from –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

The purpose of this method is to read a block (set of bytes). You may create 1GB block and repeat a read method four times.

Thank you for you help. I thought offset of FileStream.Read is offset of file. I understand now. Thanks.