Browse Source

Close the FileOutputStream in FileUtils.java file (#7937)

Close the FileOutputStream in FileUtils.java file
3.0.0/version-upgrade
Ivan0626 3 years ago committed by GitHub
parent
commit
b807c677ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java

6
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;
}

Loading…
Cancel
Save