Here you can find the source of writeStringToFile(File f, String content, boolean append)
public static boolean writeStringToFile(File f, String content, boolean append)
//package com.java2s; //License from project: Open Source License import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.logging.Logger; public class Main { static final Logger log = Logger.getLogger("Utils"); public static boolean writeStringToFile(File f, String content, boolean append) { PrintWriter fout = null;//from w ww . j a v a2s . c o m try { fout = new PrintWriter(new BufferedWriter(new FileWriter(f, append))); fout.print(content); fout.flush(); fout.close(); return true; } catch (FileNotFoundException e) { warn("File " + f + " not found: " + e.getMessage()); } catch (IOException e) { warn("IO Exception: " + e.getMessage()); } finally { if (fout != null) { fout.flush(); fout.close(); } } return false; } private static void warn(String msg) { log.warning(msg); } }