code: public static BufferedWriter newWriter(File file, String charset, boolean append) throws IOException {
          if (append) {
              return new EncodingAwareBufferedWriter(new OutputStreamWriter(new FileOutputStream(file, append), charset));
          } else {
              // first write the Byte Order Mark for Unicode encodings
              FileOutputStream stream = new FileOutputStream(file);
              writeUTF16BomIfRequired(charset, stream);
              return new EncodingAwareBufferedWriter(new OutputStreamWriter(stream, charset));
          }
      }
docs: Helper method to create a buffered writer for a file.  If the given
  charset is "UTF-16BE" or "UTF-16LE", the requisite byte order mark is
  written to the stream before the writer is returned.
  
  @param file    a File
  @param charset the name of the encoding used to write in this file
  @param append  true if in append mode
  @return a BufferedWriter
  @throws IOException if an IOException occurs.
  @since 1.0