Here you can find the source of writeFile(String str, File f)
public static void writeFile(String str, File f) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.Reader; public class Main { public static void writeFile(String str, File f) throws IOException { if (!f.exists()) { if (!f.getParentFile().exists() && !f.getParentFile().mkdirs()) throw new IOException("Unable to create dirs for file"); if (!f.createNewFile()) throw new IOException("Unable to create file"); }/*from w w w . j a v a 2 s . co m*/ FileWriter w = new FileWriter(f); w.write(str); w.close(); } public static void close(InputStream is) { if (is != null) try { is.close(); } catch (IOException e) { } } public static void close(OutputStream os) { if (os != null) try { os.close(); } catch (IOException e) { } } public static void close(Reader r) { if (r != null) try { r.close(); } catch (IOException e) { } } }