I want the most performat way to read and parse a file.
Is it possible to read a file in .NET, but not load the entire file into memory? i.e. just load the file line by line as I parse the content of each row?
Does XmlTextReader load the entire file into memory or does it stream the file into memory as it reads the file?
You could use the ReadLine method of StreamReader Class:
string line;
// Read the file and display it line by line.
System.IO.StreamReader file =
new System.IO.StreamReader("c:\\test.txt");
while((line = file.ReadLine()) != null)
{
Console.WriteLine (line);
}
file.Close();
For XML files I would go with XMLTextReader. See this article on Dr. Dobb's Journal:
"Parsing XML Files in .NET Using C#: Five different parsing techniques are available in .NET, and each has its own advantages"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With