码迷,mamicode.com
首页 > Windows程序 > 详细

[C#]统计文本文件txt中的行数(快速读取)

时间:2017-11-08 17:37:45      阅读:401      评论:0      收藏:0      [点我收藏+]

标签:file   ++   public   reader   统计   rest   lin   new   name   

快速统计文本文件中的行数( 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         }

 

  

[C#]统计文本文件txt中的行数(快速读取)

标签:file   ++   public   reader   统计   rest   lin   new   name   

原文地址:http://www.cnblogs.com/ttkl/p/7640199.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!