Java - Write code to save string to a file(recover).

Requirements

Write code to save string to a file(recover).

Demo

//package com.book2s;

import java.io.BufferedWriter;
import java.io.File;

import java.io.FileOutputStream;

import java.io.OutputStreamWriter;

public class Main {
    /**/*  ww w. j a va2s .  co m*/
     * save string to a file(recover).
     * 
     * @param file
     * @param content
     * @return success flag.
     */
    public static final boolean saveString2File(File file, String content) {
        try {
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
                    new FileOutputStream(file)));
            bw.write(content);
            bw.close();
            return true;
        } catch (Exception e) {
            return false;
        }
    }
}