In Java, is there any method to read a particular line from a file? For example, read line 32 or any other line number.
For small files:
String line32 = Files.readAllLines(Paths.get("file.txt")).get(32)
For large files:
try (Stream<String> lines = Files.lines(Paths.get("file.txt"))) { line32 = lines.skip(31).findFirst().get(); }
1.4m articles
1.4m replys
5 comments
57.0k users