How to get Number Of Lines without Reading File To End

前端 未结 3 1787
没有蜡笔的小新
没有蜡笔的小新 2021-02-07 08:43

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 Att

3条回答
  •  旧巷少年郎
    2021-02-07 09:24

    As Guffa and Jason said, there is no way to get the lines other than reading to the end.

    To solve your problem differently:

    If you are interested only in the percentage display you COULD try to acummulate that value from the total file size and the line you are currently at. You need to apply some voodoo tricks there to get the actual bytes read (like say, you have read to line 10, and a total of 200 bytes or whatever) and the file size is 400bytes. You could probably guess that you are at 50%, without giving needing to know a total line number.

    Thats just some random numbers there, btw.

提交回复
热议问题