//输出结果为csv文件
public static void Text2csv(List<String> list) throws Exception {
// 如果该目录下不存在该文件,则文件会被创建到指定目录下。如果该目录有同名文件,那么该文件将被覆盖。
String FilePath = "result.csv";
File file = new File(FilePath);
if (!file.exists()) {
file.createNewFile();
}
try {
//通过BufferedReader类创建一个使用默认大小输出缓冲区的缓冲字符输出流
BufferedWriter writeText = new BufferedWriter(new FileWriter(FilePath, true));
//调用write的方法将字符串写到流中
for (String text : list) {
writeText.append(text);
writeText.newLine(); //换行
}
writeText.flush();
writeText.close();
} catch (FileNotFoundException e) {
System.out.println("没有找到指定文件");
} catch (IOException e) {
System.out.println("文件读写出错");
}
}