Reading a specific line from a text file in Java

String line = FileUtils.readLines(file).get(lineNumber); would do, but it still has the efficiency problem. Alternatively, you can use: LineIterator it = IOUtils.lineIterator( new BufferedReader(new FileReader(“file.txt”))); for (int lineNumber = 0; it.hasNext(); lineNumber++) { String line = (String) it.next(); if (lineNumber == expectedLineNumber) { return line; } } This will be slightly more efficient due to the … Read more