How can I read/stream a file without loading the entire file into memory?
Here’s an example of how to read a file in chunks of 1KB without loading the entire contents into memory: const int chunkSize = 1024; // read the file by chunks of 1KB using (var file = File.OpenRead(“foo.dat”)) { int bytesRead; var buffer = new byte[chunkSize]; while ((bytesRead = file.Read(buffer, 0, buffer.Length)) > 0) { … Read more