本文介绍了文本文件转换为 Java List<String>使用 Commons 或 Guava的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Commons 或 Guava 库将每行文本(来自文本文件)放入 LinkedList(作为 String 对象)或其他一些集合的最优雅的方法是什么.

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.

推荐答案

这里是如何使用 Guava:

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

参考:

这篇关于文本文件转换为 Java List<String>使用 Commons 或 Guava的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 06:12