首页 > 编程语言 > 详细

【记录】java 写入内容到文件 自定义文件类型

时间:2020-07-18 14:25:36      阅读:43      评论:0      收藏:0      [点我收藏+]

import org.apache.commons.lang3.StringUtils;
import org.springframework.util.ObjectUtils;

public
static boolean writeData2File(String exportPath,String content, String fileName) { boolean flag = false; BufferedWriter out = null; try { if (!ObjectUtils.isEmpty(content) && StringUtils.isNotEmpty(fileName)) { fileName = fileName + ".java"; File pathFile = new File(exportPath); if (!pathFile.exists()) { pathFile.mkdirs(); } String relFilePath = exportPath + File.separator + fileName; File file = new File(relFilePath); if (!file.exists()) { file.createNewFile(); } out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8")); out.write(content); out.newLine(); flag = true; } } catch (IOException e) { e.printStackTrace(); } finally { if (out != null) { try { out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } } return flag; } }

 

【记录】java 写入内容到文件 自定义文件类型

原文:https://www.cnblogs.com/wbl001/p/13334688.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!