Java tutorial
//package com.java2s; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; public class Main { public static OutputStreamWriter newNovelWriter(String filepath, String encoding) throws IOException { OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(filepath), encoding); if (encoding.equals("UTF-16LE")) { // inject BOM writer.write("\uFEFF"); } return writer; } }