Text file into Java List using Commons or Guava

前端 未结 7 604
灰色年华
灰色年华 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 01:57

    Here's how to do it with Guava:

    List lines = Files.readLines(new File("myfile.txt"), Charsets.UTF_8);
    

    Reference:

    • Files.readLines(File, Charset)

提交回复
热议问题