Here you can find the source of writeFile(String filename, String content)
public static void writeFile(String filename, String content) throws IOException
//package com.java2s; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; public class Main { public static void writeFile(String filename, String content) throws IOException { File file = new File(filename); if (!file.exists()) { file.createNewFile();/* ww w . j a va 2 s .com*/ } FileOutputStream fos = new FileOutputStream(file); OutputStreamWriter writer = null; try { writer = new OutputStreamWriter(fos, "UTF-8"); writer.write(content); writer.flush(); } finally { if (writer != null) writer.close(); } } }