Reading a specific line from a text file in Java

后端 未结 9 747
隐瞒了意图╮
隐瞒了意图╮ 2020-11-27 07:34

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)
         


        
9条回答
  •  时光取名叫无心
    2020-11-27 07:54

    guava has something similar:

    List Files.readLines(File file, Charset charset);
    

    So you can do

    String line = Files.readLines(file, Charsets.UTF_8).get(lineNumber);
    

提交回复
热议问题