Sets.newHashSet(Files.readLines(file, charSet));
Set<String> lines = new HashSet<String>(FileUtils.readLines(new File("foo.txt")));
FileUtils 类和 readlines 方法。
Multiset 可以存储重复的字符串。 (添加订购)
Multiset<String> set = LinkedHashMultiset.create();
Apache Commons IO,您有 readLines
readLines
List
。然后,您可以将返回列表中的所有元素添加到您的
HashSet
中(注意:
和
Set
之间的类型兼容性,并丢失重复行)。
try (Stream lines = Files.lines(p)) { return (Set<String>) lines.collect(Collectors.toSet()); }