code: public static BufferedWriter createWriter(File file) throws IOException {
          OutputStream os = new FileOutputStream(file);
          if (file.getName().toLowerCase().endsWith(".gz"))
              os = new GZIPOutputStream(os);
          return new BufferedWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8));
      }
docs: Creates a writer from the given file. Supports GZIP compressed files.
  @param file file to write
  @return writer