Here you can find the source of writeFile(String filePath, String templetContent, String charsetName)
public static boolean writeFile(String filePath, String templetContent, String charsetName)
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { public static boolean writeFile(String filePath, String templetContent) { return writeFile(filePath, templetContent, "UTF-8"); }/* w w w . j a v a2 s . co m*/ public static boolean writeFile(String filePath, String templetContent, String charsetName) { boolean isSucc = false; try { if (filePath != null && !filePath.equals("")) { File file = new File(filePath.substring(0, filePath.lastIndexOf(File.separator))); if (file.exists() == false) { file.mkdirs(); } } FileOutputStream fout = new FileOutputStream(filePath); OutputStreamWriter out = new OutputStreamWriter(new BufferedOutputStream(fout), charsetName); out.write(templetContent); out.close(); fout.close(); isSucc = true; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return isSucc; } }