code: public static void write(Path self, String text, String charset, boolean writeBom) throws IOException {
          Writer writer = null;
          try {
              OutputStream out = Files.newOutputStream(self);
              if (writeBom) {
                  IOGroovyMethods.writeUTF16BomIfRequired(out, charset);
              }
              writer = new OutputStreamWriter(out, Charset.forName(charset));
              writer.write(text);
              writer.flush();
  
              Writer temp = writer;
              writer = null;
              temp.close();
          } finally {
              closeWithWarning(writer);
          }
      }
docs: Write the text to the Path, using the specified encoding.  If the given
  charset is "UTF-16BE" or "UTF-16LE" (or an equivalent alias) and
  <code>writeBom</code> is <code>true</code>, the requisite byte order
  mark is written to the file before the text.
  
  @param self     a Path
  @param text     the text to write to the Path
  @param charset  the charset used
  @param writeBom whether to write a BOM
  @throws java.io.IOException if an IOException occurs.
  @since 2.5.0