Java Text File Write writeStringToFile(String string, File destFile)

Here you can find the source of writeStringToFile(String string, File destFile)

Description

Includes workaround for bug: http://bugs.sun.com/bugdatabase/view_bug.do;:YfiG?bug_id=4117557

License

BSD License

Parameter

Parameter Description
string a parameter
destFile a parameter

Declaration

public static void writeStringToFile(String string, File destFile) 

Method Source Code

//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();
        }

    }
}

Related

  1. writeStringToFile(String str, File file)
  2. writeStringToFile(String str, File file)
  3. WriteStringToFile(String str, String file)
  4. writeStringToFile(String str, String filePath)
  5. writeStringToFile(String str, String filePath)
  6. writeStringToFile(String string, File dstFile)
  7. writeStringToFile(String string, File file)
  8. writeStringToFile(String string, File file)
  9. writeStringToFile(String string, File file)