Here you can find the source of writeFile(String string, File location, boolean forceASCII)
public static boolean writeFile(String string, File location, boolean forceASCII)
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { public static boolean writeFile(String string, File location) { return writeFile(string, location, false); }/* ww w .j a va 2 s. c o m*/ public static boolean writeFile(String string, File location, boolean forceASCII) { if (!location.exists()) location.getParentFile().mkdirs(); try { if (location.exists()) location.delete(); location.createNewFile(); if (!forceASCII) { FileWriter fstream = new FileWriter(location); BufferedWriter out = new BufferedWriter(fstream); out.write(string); out.close(); } else { Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(location), "ASCII")); try { out.write(string); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } finally { out.close(); } } } catch (Exception e) { System.err.println("Error: " + e.getMessage()); return false; } return true; } public static boolean delete(File resource) { if (resource.isDirectory()) { File[] childFiles = resource.listFiles(); for (File child : childFiles) { delete(child); } } return resource.delete(); } }