Readline命令正在跳过行

时间:2013-09-24 20:01:18

标签: c# readline

我正在尝试从.txt文件中读取数据并将其放在类实例列表中。在调试时,我注意到ReadLine()命令正在跳过.txt文件的行。有谁知道为什么会这样,以及如何纠正这种情况?

string logPath;
string defaultPath;
string line;

OpenFileDialog openLog = new OpenFileDialog();
openLog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";

if (openLog.ShowDialog() == DialogResult.OK)
{
    logPath = openLog.FileName;
    logTextBox.Text = logPath;
    defaultPath = logPath.Substring(0, logPath.LastIndexOf("\\"));

    StreamReader logStream = new StreamReader(logPath);

    while (!logStream.EndOfStream)
    {
        line = logStream.ReadLine();
        Console.WriteLine(line);
    }
}

0 个答案:

没有答案