Is it possible to read a large binary file from a particular position?
I don't want to read the file from the beginning because I can calculate the start position and the length of the stream I need.
According to @shenhengbin answord.
Use BinaryReader.BaseStream.Seek.
using (BinaryReader b = new BinaryReader(File.Open("perls.bin", FileMode.Open)))
{
int pos = 50000;
int required = 2000;
// Seek to our required position.
b.BaseStream.Seek(pos, SeekOrigin.Begin);
// Read the next 2000 bytes.
byte[] by = b.ReadBytes(required);
}
Well if you know streams, why not using (File)Stream.Seek(...) ?
Positionproperty, or use theSeekmethod. Are you worried that the entire file is loaded into memory?