From c6928e6b75a4000f7f50ab259842a23309c1b72c Mon Sep 17 00:00:00 2001 From: Simon Bin Date: Wed, 15 May 2024 18:57:09 +0200 Subject: [PATCH] fix corrupt files on overwrite bug --- .../src/main/java/org/aksw/commons/io/util/FileUtils.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/aksw-commons-io-parent/aksw-commons-io-utils/src/main/java/org/aksw/commons/io/util/FileUtils.java b/aksw-commons-io-parent/aksw-commons-io-utils/src/main/java/org/aksw/commons/io/util/FileUtils.java index e0fb2684..27a8de1b 100644 --- a/aksw-commons-io-parent/aksw-commons-io-utils/src/main/java/org/aksw/commons/io/util/FileUtils.java +++ b/aksw-commons-io-parent/aksw-commons-io-utils/src/main/java/org/aksw/commons/io/util/FileUtils.java @@ -42,7 +42,11 @@ public static OutputStream newOutputStream(OutputConfig config) throws IOExcepti result = StdIo.openStdOutWithCloseShield(); } else { Path path = Path.of(fileName); - result = Files.newOutputStream(path, allowOverwrite ? StandardOpenOption.CREATE : StandardOpenOption.CREATE_NEW); + if (allowOverwrite) { + result = Files.newOutputStream(path, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); + } else { + result = Files.newOutputStream(path, StandardOpenOption.CREATE_NEW); + } } return result;