相关疑难解决方法(0)

如何在.NET中读取大型(1 GB)txt文件?

我有一个1 GB的文本文件,我需要逐行阅读.最好和最快的方法是什么?

private void ReadTxtFile()
{            
    string filePath = string.Empty;
    filePath = openFileDialog1.FileName;
    if (string.IsNullOrEmpty(filePath))
    {
        using (StreamReader sr = new StreamReader(filePath))
        {
            String line;
            while ((line = sr.ReadLine()) != null)
            {
                FormatData(line);                        
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

FormatData()我检查线必须以一个字相匹配,并基于该增量的整数变量的起始字.

void FormatData(string line)
{
    if (line.StartWith(word))
    {
        globalIntVariable++;
    }
}
Run Code Online (Sandbox Code Playgroud)

c#

55
推荐指数
6
解决办法
8万
查看次数

标签 统计

c# ×1