快速统计文本文件中的行数( StreamReader.ReadLine() ):
测试代码如下:
1 //读取txt文件中总行数的方法 2 public static int requestMethod(String _fileName) 3 { 4 Stopwatch sw = new Stopwatch(); 5 var path = _fileName; 6 int lines = 0; 7 8 //按行读取 9 sw.Restart();10 using (var sr = new StreamReader(path))11 {12 var ls = "";13 while ((ls = sr.ReadLine()) != null)14 {15 lines++;16 }17 }18 sw.Stop();19 return lines;20 }