Text file into Java List using Commons or Guava

前端 未结 7 530
灰色年华
灰色年华 2021-01-08 01:18

What is the most elegant way to put each line of text (from the text file) into LinkedList (as String object) or some other collection, using Commons or Guava libraries.

7条回答
  •  抹茶落季
    2021-01-08 02:06

    Using Apache Commons IO, you can use FileUtils#readLines method. It is as simple as:

    List lines = FileUtils.readLines(new File("..."));
    for (String line : lines) {
      System.out.println(line);  
    }
    

提交回复
热议问题