Here you can find the source of writeStringToFile(String filename, String str)
public static void writeStringToFile(String filename, String str)
//package com.java2s; //License from project: Academic Free License import java.io.FileWriter; import java.io.InputStream; import java.io.OutputStream; import java.io.Reader; import java.io.Writer; public class Main { public static void writeStringToFile(String filename, String str) { writeStringToFile(filename, str, false); }//from www .j a v a 2 s . c o m public static void writeStringToFile(String filename, String str, boolean append) { FileWriter fw = null; try { fw = new FileWriter(filename, append); fw.write(str); fw.flush(); fw.close(); fw = null; } catch (Exception ex) { ex.printStackTrace(); } finally { close(fw); } } /** * Close the output stream and trap any exceptions. */ public static void close(OutputStream os) { if (os != null) { try { os.close(); } catch (Exception ex) { } } } public static void close(Writer fw) { if (fw != null) { try { fw.close(); } catch (Exception ex) { } ; } } /** * Close the input stream and trap any exceptions. */ public static void close(InputStream is) { if (is != null) { try { is.close(); } catch (Exception ex) { } } } /** * Close the reader. * * @param r */ public static void close(Reader r) { if (r != null) { try { r.close(); } catch (Exception ex) { } } } }