Skip to content

Commit

Permalink
Using Files.writeString on JRE 11 to append files
Browse files Browse the repository at this point in the history
  • Loading branch information
mkarg committed Jan 21, 2023
1 parent 7983d57 commit 0c05270
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java11/org/codehaus/plexus/util/BaseFileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;

/**
* Implementation specific to Java SE 11 version.
Expand All @@ -26,4 +27,17 @@ static void fileWrite( Path path, String encoding, String data ) throws IOExcept
Files.writeString( path, data );
}
}

static void fileAppend( Path path, String encoding, String data ) throws IOException
{
if ( encoding != null )
{
Files.writeString( path, data, Charset.forName( encoding ),
StandardOpenOption.APPEND, StandardOpenOption.CREATE );
}
else
{
Files.writeString( path, data,StandardOpenOption.APPEND, StandardOpenOption.CREATE );
}
}
}

0 comments on commit 0c05270

Please sign in to comment.