Skip to content

Commit

Permalink
fix corrupt files on overwrite bug
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonBin committed May 15, 2024
1 parent b72db28 commit c6928e6
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c6928e6

Please sign in to comment.