Skip to content

Instantly share code, notes, and snippets.

@arnabdas
Created October 5, 2018 04:23
Show Gist options
  • Select an option

  • Save arnabdas/fa31abb02f31fb3a192c353e86615687 to your computer and use it in GitHub Desktop.

Select an option

Save arnabdas/fa31abb02f31fb3a192c353e86615687 to your computer and use it in GitHub Desktop.
Read a large file and write the processed data into a stream
// https://stackoverflow.com/questions/2161895/reading-large-text-files-with-streams-in-c-sharp
// https://docs.microsoft.com/en-us/dotnet/standard/io/how-to-write-text-to-a-file
using (FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (BufferedStream bs = new BufferedStream(fs))
using (StreamReader sr = new StreamReader(bs))
using (StreamWriter outputFile = new StreamWriter(Path.Combine(mydocpath,"WriteLines.txt")))
{
string line;
while ((line = sr.ReadLine()) != null)
{
outputFile.WriteLine(line);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment