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.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
using org.apache.commons.io.FileUtils
They are pretty similar, with Commons IO it will look like this:
Main advantage of Guava is the specification of the charset (no typos):
I'm not sure if you only want to know how to do this via Guava or Commons IO, but since Java 7 this can be done via
java.nio.file.Files.readAllLines(Path path, Charset cs)
(javadoc).Since this is part of the Java SE it does not require you to add any additional jar files (Guava or Commons) to your project.
Using Apache Commons IO, you can use
FileUtils#readLines
method. It is as simple as:This is probably what youre looking for
FileUtils.readLines(File file)
Here's how to do it with Guava:
Reference:
Files.readLines(File, Charset)