如果需要逐行读取一个文本文件,可以使用System.IO.StreamReader对象及其Peek和ReadLine方法,如下例:
private void ReadTextFile(string fileName)
{
// Open and read the text file line by line
StreamReader srFile = new StreamReader(fileName,true);
while(srFile.Peek() > -1) // Check EOF
{
string sLine = srFile.ReadLine(); // Read one line
// ...
}
srFile.Close();
}
|

博客介绍了逐行读取文本文件的方法,可使用System.IO.StreamReader对象及其Peek和ReadLine方法来实现。
1852

被折叠的 条评论
为什么被折叠?



