What is the most optimal way to read in a very large text file? Should it be read all at once (ReadToEnd?) or Line by Line?. This may be related to: What's the fastest way to read a text file line-by-line?
using (StreamReader sr = new StreamReader("TestFile.txt"))
{
String line = sr.ReadToEnd();
}
OR
System.IO.StreamReader file =
new System.IO.StreamReader("c:\\test.txt");
while((line = file.ReadLine()) != null)
{
// append to StringBuilder
}
Should one store text file to string? or StringBuilder? What's the best approach?