Here you can find the source of writeFile(String path, String fileName, String content, String charset)
public static String writeFile(String path, String fileName, String content, String charset) throws IOException
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { public static String writeFile(String path, String fileName, String content) throws IOException { return writeFile(path, fileName, content, "UTF-8"); }//w w w . j av a 2 s . c o m public static String writeFile(String path, String fileName, String content, String charset) throws IOException { mkDir(path); String filePath = path + File.separator + fileName; File file = new File(filePath); if (file.exists()) { file.delete(); } file.createNewFile(); FileOutputStream fops = new FileOutputStream(file); fops.write(content.getBytes(charset)); fops.flush(); fops.close(); return filePath; } public static void mkDir(String path) { File file = new File(path); if (!file.exists()) { file.mkdirs(); } } }