Text file into Java List<String> using Commons or Guava

MatBanik picture MatBanik · Jan 2, 2011 · Viewed 18.5k times · Source

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.

Answer

Sean Patrick Floyd picture Sean Patrick Floyd · Jan 2, 2011

Here's how to do it with Guava:

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

Reference: