/**
* 创建文件
*
* @param filePath 文件目录
* @param fileName 文件名
* @param content 内容
* @return
*/
public Boolean createFile(String filePath, String fileName, String content) {
try {
Files.createDirectories(Paths.get(filePath));
log.info("创建目录成功: filePath = {}", filePath);
} catch (IOException e) {
log.error("创建目录失败: filePath = {}", filePath, e);
return false;
}
try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(filePath, fileName))) {
writer.write(content);
writer.flush();
log.info("文件写入成功: filePath = {}, fileName = {}", filePath, fileName);
} catch (IOException e) {
log.error("文件写入失败: filePath = {}, content = {}", filePath, content, e);
return false;
}
return true;
}