public void exportToCsvFile(List<StraffPhoneEntity> list, String fileName){
if (list!=null && list.size() > 0){
String filePath = proMapper.selectByKeyid(STAFF_INFO_CVS_PATH);
File csvFile = null;
BufferedWriter csvWriter = null;
try {
System.out.println("文件地址为:"+filePath + File.separator + fileName);
csvFile = new File(filePath + File.separator + fileName);
File parent = csvFile.getParentFile();
if (parent != null && !parent.exists()) {
parent.mkdirs();
}
csvFile.createNewFile();
csvWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(csvFile), "GB2312"), 1024);
for (StraffPhoneEntity points : list) {
csvWriter.write(JSON.toJSONString(points));
csvWriter.newLine();
}
csvWriter.flush();
System.out.println("生成手机TXT文件成功");
} catch (Exception e) {
System.out.println("生成手机TXT文件失败");
e.printStackTrace();
} finally {
try {
csvWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}