Skip to content

Instantly share code, notes, and snippets.

@hunterwei
Created April 17, 2018 18:10
Show Gist options
  • Save hunterwei/94a3c704c79c24867da2d05191ab4626 to your computer and use it in GitHub Desktop.
Save hunterwei/94a3c704c79c24867da2d05191ab4626 to your computer and use it in GitHub Desktop.
Read Extremely large file efficiently in C#
using (FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (BufferedStream bs = new BufferedStream(fs))
using (StreamReader sr = new StreamReader(bs))
{
string line;
while ((line = sr.ReadLine()) != null)
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment