我需要逐行读取一个日志文件,该文件大小约为6MB,共有40000行。但是在测试我的程序后,我发现该日志文件只使用LF字符作为分隔符。因此,我无法使用StreamReader
类的Readline
方法。
我该如何解决这个问题?
编辑:我尝试使用文本阅读器,但我的程序仍然无法正常工作:
using (TextReader sr = new StreamReader(strPath, Encoding.Unicode))
{
sr.ReadLine(); //ignore three first lines of log file
sr.ReadLine();
sr.ReadLine();
int count = 0; //number of read line
string strLine;
while (sr.Peek()!=0)
{
strLine = sr.ReadLine();
if (strLine.Trim() != "")
{
InsertData(strLine);
count++;
}
}
return count;
}