StreamReader ReadLine returns null when not EOF

谁说胖子不能爱 提交于 2019-12-08 06:26:26

Have you tried a more traditional approach to reading the stream? This way your checking for the end of the stream before reading the next potentially empty/null line. Seems like your code should work, but with a possible null exception thrown for trying to read a line that doesn't exists(not sure if SR throws for that though).

 using (StreamReader SR = new StreamReader(OFD.FileName))
 {
     while (!SR.EndOfStream)
     {
         string CurrentLine = SR.ReadLine();
         var eventRetVal = loadFileLineEvent(CurrentLine);
     }
 }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!