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)
Not that I'm aware of.
Be aware that there's no particular indexing on files as to where the line starts, so any utility method would be exactly as efficient as:
BufferedReader r = new BufferedReader(new FileReader(file));
for (int i = 0; i < lineNumber - 1; i++)
{
r.readLine();
}
return r.readLine();
(with appropriate error-handling and resource-closing logic, of course).