Here you can find the source of writeStringToFile(String s, File f)
public static void writeStringToFile(String s, File f) throws IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileWriter; import java.io.IOException; public class Main { public static void writeStringToFile(String s, File f) throws IOException { if (f.exists()) { if (!f.delete()) { throw new RuntimeException("Cannot delete file " + f.getAbsolutePath()); }//www.j a v a2s . c o m } FileWriter fw = null; try { if (!f.createNewFile()) { throw new RuntimeException("Cannot create new file : " + f.getAbsolutePath()); } fw = new FileWriter(f); fw.write(s); } catch (IOException e) { throw (e); } finally { if (fw != null) { try { fw.close(); } catch (IOException e) { throw (e); } } } } }