如果有一個csv文件,其數據會隨時增加。現在我需要做的是讀最後的30,000行。讀取文件的最後30,000行
代碼:
string[] lines = File.ReadAllLines(Filename).Where(r => r.ToString() != "").ToArray();
int count = lines.Count();
int loopCount = count > 30000 ? count - 30000 : 0;
for (int i = loopCount; i < lines.Count(); i++)
{
string[] columns = lines[i].Split(',');
orderList.Add(columns[2]);
}
它工作正常,但問題是
File.ReadAllLines(Filename)
閱讀這會導致性能缺乏一個完整的文件。我想要的東西只讀取最後30,000行,通過整個文件迭代。
PS:我正在使用.Net 3.5。 .net 3.5中不存在Files.ReadLines()
http://stackoverflow.com/questions/4619735/how-to-read-last-n-lines-of-log-file http://stackoverflow.com/questions/398378/get-last-10 - 超大文本文件-10gb -c-sharp/398512#398512 – Ofiris