|
@@ -138,16 +138,20 @@ public class FileUtils {
|
|
* @return true if write success
|
|
* @return true if write success
|
|
*/
|
|
*/
|
|
public static boolean writeContent2File(String content, String filePath) {
|
|
public static boolean writeContent2File(String content, String filePath) {
|
|
|
|
+ FileOutputStream fos = null;
|
|
try {
|
|
try {
|
|
File distFile = new File(filePath);
|
|
File distFile = new File(filePath);
|
|
if (!distFile.getParentFile().exists() && !distFile.getParentFile().mkdirs()) {
|
|
if (!distFile.getParentFile().exists() && !distFile.getParentFile().mkdirs()) {
|
|
logger.error("mkdir parent failed");
|
|
logger.error("mkdir parent failed");
|
|
return false;
|
|
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) {
|
|
} catch (IOException e) {
|
|
logger.error(e.getMessage(), e);
|
|
logger.error(e.getMessage(), e);
|
|
return false;
|
|
return false;
|
|
|
|
+ } finally {
|
|
|
|
+ IOUtils.closeQuietly(fos);
|
|
}
|
|
}
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|