如下java代码导出的csv文件用Excel打开还是乱码, 用Sublime Text的Save with Encoding -> UTF-8 with BOM
public static void exportWithOpencsvBySql(String sql, String file) throws Exception {
OutputStreamWriter ows = new OutputStreamWriter(new FileOutputStream(new File("/tmp/" + file)), "utf-8");
try {
CSVWriter writer = new CSVWriter(ows);
System.out.println("file: " + file);
Connection connection = getConnection();
ResultSet myResultSet = getResultSet(connection, sql);
writer.writeAll(myResultSet, true);
writer.close();
closeConnection(connection);
} catch (IOException e) {
e.printStackTrace();
}
}