How can I get a specific line from a text file? [duplicate]
问题 This question already has answers here : How to read a specific line using the specific line number from a file in Java? (17 answers) Closed 4 years ago . I don't know how to get a specific line of text from a file. Let's say the text file is: (1) john (2) mark (3) Luke How can I get the second line of the text file (mark)? I just need to read it, not to edit it. 回答1: int n = 2; String lineN = Files.lines(Paths.get("yourFile.txt")) .skip(n) .findFirst() .get(); For pre-Java 8, you could do