code: public static File appendToFile(String filename, String extraContent, boolean onNewLine){
          PrintWriter pw = null;
          try {
              pw = new PrintWriter(
                      new BufferedWriter(
                              new OutputStreamWriter(
                                      new FileOutputStream(filename, true),
                                      FILE_ENCODING)
                      )
              );
              if (onNewLine) {
                  pw.println();
              }
              pw.print(extraContent);
          } 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: Appends the extra content to the file, in UTF-8 encoding.
  @param filename  file to create or append to.
  @param extraContent   extraContent to write.
  @param onNewLine whether a new line should be created before appending the extra content
  @return file reference to file.