Here you can find the source of writeFile(File f, String str)
public static void writeFile(File f, String str) throws Exception
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { /**//from ww w . ja v a 2 s .com * Writes a string(str) to a File(f) ** THis method overwrites any data in the file */ public static void writeFile(File f, String str) throws Exception { if (!f.exists()) { if (!f.createNewFile()) { throw new Exception("File was not created!"); } } if (!f.canWrite()) throw new Exception("No permission to write file!"); else { try { // WE CAN WRITE TO THE FILE FileWriter fw = new FileWriter(f, false); fw.write(str); fw.close(); } catch (Exception e) { throw e; } } } }