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)
I agree it's trivial to implement, but it's not very efficient specially if the file is very big.
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.
If you are going to work with the same file in the same way (looking for a text at certain line) you can index your file. Line number -> offset.
According to this answer, Java 8 enables us to extract specific lines from a file. Examples are provided in that answer.