Java tutorial
//package com.java2s; import java.io.*; public class Main { /** * Opens a buffered writer that uses UTF-8 encoding. * TODO: handle compression automatically based on file extension. * @param path * @return * @throws IOException */ public static BufferedWriter openWriter(File path) throws IOException { return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path), "UTF-8")); } public static Writer openWriter(String path) throws IOException { return openWriter(new File(path)); } }