Here you can find the source of writeStringToFile(String string, File destFile)
Includes workaround for bug: http://bugs.sun.com/bugdatabase/view_bug.do;:YfiG?bug_id=4117557
Parameter | Description |
---|---|
string | a parameter |
destFile | a parameter |
public static void writeStringToFile(String string, File destFile)
//package com.java2s; /**/*from w w w. jav a 2s . co m*/ * <p> * Utilities for manipulating Paths, Files, Directories, etc. * </p> * <p> * <span class="BSDLicense"> This software is distributed under the <a * href="http://hci.stanford.edu/research/copyright.txt">BSD License</a>.</span> * </p> * * @author <a href="http://graphics.stanford.edu/~ronyeh">Ron B Yeh</a> (ronyeh(AT)cs.stanford.edu) */ import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintWriter; public class Main { /** * Includes workaround for bug: http://bugs.sun.com/bugdatabase/view_bug.do;:YfiG?bug_id=4117557 * * @param string * @param destFile * @created Jun 5, 2006 * @author Ron Yeh */ public static void writeStringToFile(String string, File destFile) { try { final FileOutputStream fos = new FileOutputStream(destFile.getAbsoluteFile()); final BufferedWriter bw = new BufferedWriter(new PrintWriter(fos)); bw.write(string); bw.flush(); bw.close(); fos.close(); // should be redundant } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }