我有一个非常大的文件,大约有 30.000 行。我必须解析这个文件并且不能删除它上面的条目。所以我的想法是跳过已经读过的行。我试过这样的事情:
//Gets the allready readed lines
int readLines = GetCurrentCounter();
//Open File
FileStream stream = new FileStream(LogDatabasePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using (StreamReader reader = new StreamReader(stream))
{
int counter = 0;
string line;
//If File was allready read to a specified line, skip these lines
if (readLines != 0) reader.ReadLine().Skip(readLines);
//Check if new lines are available
while ((line = reader.ReadLine()) != null)
{
if (counter >= readedLines)
{
//If there is text which contains the searched Testsystem-Name
if (line.Contains(TestSystemName.ToUpper()))
{
//Create new Database-Entry
new TestsystemError().GenerateNewDatabaseEntry(line, counter);
}
}
System.Console.WriteLine(line);
counter++;
}
}
问题是,功能 reader.ReadLine().Skip(readLines) 没有功能,或者我以错误的方式使用它。
我需要在不使用函数“reader.ReadLine()”的情况下跳过行,因为这非常慢(如果我必须遍历所有行 ~ 大约 30.000 行,我会遇到性能问题)。
有没有办法跳过行?如果是这样,分享代码会很棒。谢谢。
哆啦的时光机
守候你守候我
回首忆惘然
相关分类