java写csv

  直接gbk, 

/**
* 写入文件,末尾自动添加\r\n
* @param path
* @param strs
*/
public static void writeLines(String path, List<String> strs, boolean is_append, String encode)
{
try
{
File file = new File(path);
if(!file.exists())
file.createNewFile();
FileOutputStream out = new FileOutputStream(file, is_append); //true表示追加
StringBuffer sb = new StringBuffer();
for (String str : strs) {
sb.append(str + "\r\n");
}
out.write(sb.toString().getBytes(encode));//
out.close();
}
catch(IOException ex)
{
System.out.println(ex.getStackTrace());
}
}
posted @ 2021-10-27 13:56  耿乾坤java  阅读(87)  评论(0)    收藏  举报