code: public static boolean writeTextFile(String _fileName, String _fileContent, Charset _charset, boolean _append) {
          if (StringUtil.isBlank(_fileName)) {
              return false;
          }
          String allText = "";
          if (_append) {
              File file = new File(_fileName);
              if (file.exists()) {
                  allText = readFileToString(file) + guessLineTerminatorOfFile(_fileName);
              }
          }
          allText += _fileContent;
  
          OutputStreamWriter writer = null;
          try {
              writer = new OutputStreamWriter(new FileOutputStream(_fileName), _charset);
              writer.write(allText);
          } catch (IOException _ex) {
              LOGGER.error("Could not write file to '" + _fileName + "'", _ex);
              return false;
          } finally {
              try {
                  if (writer != null) {
                      writer.close();
                  }
              } catch (IOException _ex) {
                  LOGGER.error("Error while closing file '" + _fileName + "'", _ex);
                  return false;
              }
          }
  
          return true;
      }
docs: Write String to file with the given charset.
  Optionally appends the data to the file.
  
  @param _fileName the file to write
  @param _fileContent the content to write
  @param _charset the charset to use
  @param _append append content to file, if false file will be overwritten if existing
  
  @return true on successful write, false otherwise