引入依赖
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
实现
public static List<String> getFileToList(String filePath) {
List<String> readFileList = null;
try {
readFileList = FileUtils.readLines(new File(filePath));
} catch (Exception e) {
e.printStackTrace();
}
assert readFileList != null;
readFileList = readFileList.parallelStream().filter(string -> !string.isEmpty()).collect(Collectors.toList());
return readFileList;
}