From 4a91edc47ec1d7f9670c461fbd0745bae6eb9508 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Sat, 23 Apr 2022 19:43:51 +0200 Subject: [PATCH] Fix regression and deprecate: FileUtils.fileAppend should create file if not exist. --- src/main/java/org/codehaus/plexus/util/FileUtils.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/codehaus/plexus/util/FileUtils.java b/src/main/java/org/codehaus/plexus/util/FileUtils.java index cac82ba3..4dca8b3c 100644 --- a/src/main/java/org/codehaus/plexus/util/FileUtils.java +++ b/src/main/java/org/codehaus/plexus/util/FileUtils.java @@ -389,6 +389,8 @@ private static InputStreamReader getInputStreamReader( File file, String encodin * @param fileName The path of the file to write. * @param data The content to write to the file. * @throws IOException if any + * @deprecated use {@code java.nio.files.Files.write(filename, data.getBytes(encoding), + * StandardOpenOption.APPEND, StandardOpenOption.CREATE)} */ public static void fileAppend( String fileName, String data ) throws IOException @@ -403,11 +405,14 @@ public static void fileAppend( String fileName, String data ) * @param encoding The encoding of the file. * @param data The content to write to the file. * @throws IOException if any + * @deprecated use {@code java.nio.files.Files.write(filename, data.getBytes(encoding), + * StandardOpenOption.APPEND, StandardOpenOption.CREATE)} */ public static void fileAppend( String fileName, String encoding, String data ) throws IOException { - try ( OutputStream out = Files.newOutputStream( Paths.get(fileName), StandardOpenOption.APPEND ) ) + try ( OutputStream out = Files.newOutputStream( Paths.get(fileName), + StandardOpenOption.APPEND, StandardOpenOption.CREATE ) ) { if ( encoding != null ) {