Number of lines in a file in Java

前端 未结 19 2674
抹茶落季
抹茶落季 2020-11-22 05:31

I use huge data files, sometimes I only need to know the number of lines in these files, usually I open them up and read them line by line until I reach the end of the file<

19条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 05:58

    If you don't have any index structures, you'll not get around the reading of the complete file. But you can optimize it by avoiding to read it line by line and use a regex to match all line terminators.

提交回复
热议问题