如何获得行数不读文件要结束 [英] How to get Number Of Lines without Reading File To End

查看:134
本文介绍了如何获得行数不读文件要结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让在一个大的文本文件中的行数,但没有读取文件内容或读取文件结束,计数++。

也许有一些文件属性,但无法找到它的。 因为我可能是在某些情况下,我应该得到线的总数和比较,当前行显示的百分比,而只是一个百分比显示这可能是愚蠢首先阅读所有内容比读它一次可以显示原始文本在用户。

最好成绩

解决方案

没有。你要读文件。想想,当你写的文件,如果你想找到它很快不计其存储在文件的开头或在一个单独的文件。

请注意,您可以流的文件,这是令人惊讶的快:

 诠释计数= File.ReadLines(路径).Count之间的();
 

  

由于我可能会在某些情况下,我应该得到线的总数和比较,当前行显示的百分比,而只是一个百分比显示这可能是愚蠢首先阅读所有内容比读它一次可以显示原始文本的用户。

喔,只是得到的文件的大小和每行的字节长度,并保持了到目前为止已处理的字节数的累积计数。

Is there a way to get Number of Lines within a Large Text file ,but without Reading the File content or reading file to end and Counting++.

Maybe there are some File Attributes ,but cannot find it out at all . Because i might be in some cases where i should get Total Number of Line's and compare it to Current line to display the Percentage,and just for a Percentage Display it might be stupid to read first all Content than read it Again to Display the raw text at user.

bests

解决方案

No. You have to read the file. Consider storing it at the beginning of the file or in a separate file when you write the file if you want to find it quickly without counting.

Note that you can stream the file, and it's surprisingly fast:

int count = File.ReadLines(path).Count();

Because i might be in some cases where i should get Total Number of Line's and compare it to Current line to display the Percentage,and just for a Percentage Display it might be stupid to read first all Content than read it Again to Display the raw text at user.

Oh, just get the file size and the length of each line in bytes and keep a cumulative count of the number of bytes processed so far.

这篇关于如何获得行数不读文件要结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆