记录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 写入内容到文件 自定义文件类型的主要内容,如果未能解决你的问题,请参考以下文章

在 PySpark 中写入数据帧的自定义文件名

如何自定义java日志文件,最多只包含N个日志记录,而不是以字节为单位的大小

如何将自定义类型的列表/数组写入 HDF5 文件?

java 删除文件中的数据

日志技术-Java原生日志实现JUL

将 PHP 错误记录到 Drupal 网站的自定义文件中