我正在尝试从.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);
}
}