code: public static void writeContent(CharSequence content, File file, String encoding) {
          OutputStream os = null;
          try {
              os = new FileOutputStream(file);
              PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(os, encoding));
              printWriter.println(content);
              printWriter.flush();
              os.flush();
          } catch (IOException e) {
              throw new RuntimeException(e);
          } finally {
              try {
                  if (os != null) os.close();
              } catch (Exception e) {
                  //
              }
          }
      }
docs: Write String content to a file (always use utf-8)
  
  @param content The content to write
  @param file    The file to write