读取和解析文件中.NET - 性能对于租用 [英] Reading and Parsing Files in .NET - Performance For Hire

查看:146
本文介绍了读取和解析文件中.NET - 性能对于租用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最想要的performat的方式来阅读和分析的文件。

I want the most performat way to read and parse a file.

是否有可能读取.NET中的文件,而不是整个文件加载到内存中?也就是,只有通过加载行的文件行我分析的每一行的内容?

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?

请问XmlTextReader将整个文件加载到内存中,或它流的文件到内存中读取文件?

Does XmlTextReader load the entire file into memory or does it stream the file into memory as it reads the file?

推荐答案

您可以使用StreamReader类的ReadLine方法:

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();

有关XML文件,我会去XMLTextReader的。查看博士道博的日记这文章:

For XML files I would go with XMLTextReader. See this article on Dr. Dobb's Journal:

使用C#解析XML文件中。NET:五个不同的解析技术是在.NET中可用,每个人都有自己的优势

"Parsing XML Files in .NET Using C#: Five different parsing techniques are available in .NET, and each has its own advantages"

这篇关于读取和解析文件中.NET - 性能对于租用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆