How to get Number Of Lines without Reading File To End

前端 未结 3 1776
没有蜡笔的小新
没有蜡笔的小新 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

    No, there is no other way.

    A file is not line based (or even character based), so there is no meta information about the number of lines (or even number of characters). The only meta data about the content is the length in bytes.

    If you have some additional information about the file, for example that each line is exactly the same length, and it uses an 8-bit encoding so that the number of characters is the same as the number of bytes, you could calculate the number of lines from the file size.

提交回复
热议问题