Java 读取TXT文件到List

public static List<String> readTxt(String filePath) {//读取TXT并获取所有信息
		List<String> fileList=new ArrayList<String>();//创建存储String的List
		try {
			fileList=Files.readAllLines(Paths.get(filePath));//读取该路径的文件
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(fileList==null) {
			return null;
		}
		return fileList;
	}

你可能感兴趣的:(Java工具模板)