Java tutorial
//package com.java2s; import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStreamWriter; public class Main { public static void writeFile(String filename, String text) throws Exception { File f = new File(filename); if (!f.exists()) f.createNewFile(); else { f.delete(); f.createNewFile(); } BufferedWriter output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename), "utf-8")); // new BufferedWriter(new FileWriter(filename, // false),"utf-8"); output.write(text); output.flush(); output.close(); } }