记录java 写入内容到文件 自定义文件类型
Posted 天道酬勤
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了记录java 写入内容到文件 自定义文件类型相关的知识,希望对你有一定的参考价值。
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 写入内容到文件 自定义文件类型的主要内容,如果未能解决你的问题,请参考以下文章