code: public static BufferedWriter newWriter(Path self, String charset, boolean append, boolean writeBom) throws IOException {
          boolean shouldWriteBom = writeBom && !self.toFile().exists();
          if (append) {
              BufferedWriter writer = Files.newBufferedWriter(self, Charset.forName(charset), CREATE, APPEND);
              if (shouldWriteBom) {
                  IOGroovyMethods.writeUTF16BomIfRequired(writer, charset);
              }
              return writer;
          } else {
              OutputStream out = Files.newOutputStream(self);
              if (shouldWriteBom) {
                  IOGroovyMethods.writeUTF16BomIfRequired(out, charset);
              }
              return new BufferedWriter(new OutputStreamWriter(out, Charset.forName(charset)));
          }
      }
docs: Helper method to create a buffered writer for a file.  If the given
  charset is "UTF-16BE" or "UTF-16LE" (or an equivalent alias), the
  requisite byte order mark is written to the stream before the writer
  is returned.
  
  @param self     a Path
  @param charset  the name of the encoding used to write in this file
  @param append   true if in append mode
  @param writeBom whether to write a BOM
  @return a BufferedWriter
  @throws java.io.IOException if an IOException occurs.
  @since 2.5.0