diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java index cf693f12c5..4754f36f28 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java @@ -138,16 +138,20 @@ public class FileUtils { * @return true if write success */ public static boolean writeContent2File(String content, String filePath) { + FileOutputStream fos = null; try { File distFile = new File(filePath); if (!distFile.getParentFile().exists() && !distFile.getParentFile().mkdirs()) { logger.error("mkdir parent failed"); return false; } - IOUtils.write(content, new FileOutputStream(filePath), StandardCharsets.UTF_8); + fos = new FileOutputStream(filePath); + IOUtils.write(content, fos, StandardCharsets.UTF_8); } catch (IOException e) { logger.error(e.getMessage(), e); return false; + } finally { + IOUtils.closeQuietly(fos); } return true; }