文章最前: 我是Octopus,这个名字来源于我的中文名--章鱼;我热爱编程、热爱算法、热爱开源。所有源码在我的个人github ;这博客是记录我学习的点点滴滴,如果您对 Python、Java、AI、算法有兴趣,可以关注我的动态,一起学习,共同进步。
java读取文件的每一行数据存储到list当中。
package com.zhang.read;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.util.List;
/**
* @description: 把文件读到list当中
* @author: zhangyu
*/
public class ReadFileToLine {
public static List<String> getFileToList(String filePath) {
List<String> readFileList = null;
try {
readFileList = FileUtils.readLines(new File(filePath));
} catch (Exception e) {
e.printStackTrace();
}
return readFileList;
}
}
增加pom.xml文件:
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>