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 .