code: public static File writeFile(String filename, String content) {
          PrintWriter pw = null;
          try {
              pw = new PrintWriter(filename, FILE_ENCODING);
              pw.write(content);
              pw.flush();
          } catch (FileNotFoundException e) {
              throw new IllegalArgumentException("Unable to write to: " + filename, e);
          } catch (UnsupportedEncodingException e) {
              throw new RuntimeException(e);
          } finally {
              if (pw != null) {
                  pw.close();
              }
          }
          return new File(filename);
      }
docs: Writes content to file, in UTF-8 encoding.
  
  @param filename file to create or overwrite.
  @param content  content to write.
  @return file reference to file.