Reading a specific line from a text file in Java

后端 未结 9 752
隐瞒了意图╮
隐瞒了意图╮ 2020-11-27 07:34

Is there any method to read a specific line from a text file ? In the API or Apache Commons. Something like :

String readLine(File file, int lineNumber)
         


        
9条回答
  •  隐瞒了意图╮
    2020-11-27 08:15

    Because files are byte and not line orientated - any general solutions complexity will be O(n) at best with n being the files size in bytes. You have to scan the whole file and count the line delimiters until you know which part of the file you want to read.

提交回复
热议问题