cdm/src/main/java/ucar/nc2/util/IO.java
static public void writeToFile(String contents, File file) throws IOException {
    try (FileOutputStream fout = new FileOutputStream(file)) {
      OutputStreamWriter fw = new OutputStreamWriter(fout, CDM.utf8Charset);
      UnsynchronizedBufferedWriter writer = new UnsynchronizedBufferedWriter(fw);
      writer.write(contents);
      writer.flush();
    }
  }
static public void writeToFile(String contents, File file) throws IOException {
    try (FileOutputStream fout = new FileOutputStream(file)) {
      OutputStreamWriter fw = new OutputStreamWriter(fout, CDM.utf8Charset);
      UnsynchronizedBufferedWriter writer = new UnsynchronizedBufferedWriter(fw);
      writer.write(contents);
      writer.flush();
    }
  }
static public void writeToFile ( String contents , File file ) throws IOException { try ( FileOutputStream fout = new FileOutputStream ( file ) ) { OutputStreamWriter fw = new OutputStreamWriter ( fout , CDM . utf8Charset ) ; UnsynchronizedBufferedWriter writer = new UnsynchronizedBufferedWriter ( fw ) ; writer . write ( contents ) ; writer . flush ( ) ; } }
Write String contents to a file, using UTF-8 encoding.

@param contents String holding the contents
@param file     write to this file (overwrite if exists)
@throws java.io.IOException on io error
Write String contents to a file using UTF - 8 encoding .