/**
* 生成csv文件
* @param str 内容
* @param dirname 目录全路径
* @param filename 文件名称
* @param isAppend 是否在后面追加
* @return
*/
public static File writeContent(String str,String dirname, String filename, boolean isAppend) {
if (dirname == null) {
return null;
}
File fileDir = new File(dirname);
if (!fileDir.exists()) {
fileDir.mkdirs();
}
File targetFile = new File(fileDir, filename);
FileOutputStream fos = null;
OutputStreamWriter writer = null;
try {
fos = new FileOutputStream(targetFile, isAppend);
writer = new OutputStreamWriter(fos,"gbk");
writer.write(str);
writer.flush();
} catch (IOException e) {
log.error(e.getMessage());
targetFile=null;
} finally {
if (writer!=null) {
try {
writer.close();
} catch (IOException e) {
log.error(e.getMessage());
}
}
if (fos!=null) {
try {
fos.close();
} catch (IOException e) {
log.error(e.getMessage());
}
}
return targetFile;
}
}
FileUtil
最新推荐文章于 2021-06-26 15:38:19 发布