XK8ER
XK8ER

Reputation: 780

Read a 2GB file with peek or read

how can I know the last HEX byte of a 2GB binary file without opening the whole file.. is there an easy and fast way of doing this without running into memory problems?

Upvotes: 2

Views: 198

Answers (2)

Simon Whitehead
Simon Whitehead

Reputation: 65079

Just Seek backwards from the end:

using (var br = new BinaryReader(File.OpenRead(@"filename.2gb"))) {
    br.BaseStream.Seek(-1, SeekOrigin.End);
    Console.WriteLine(br.ReadByte()); // last byte
}

Upvotes: 7

mvp
mvp

Reputation: 116197

Just open a file and use FileStream.Seek method to 2GB offset. This will be fast and will not cause any memory problems.

Upvotes: 1

Related Questions