Reputation: 780
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
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
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