Java FileWriter Write save(File file, String text)

Here you can find the source of save(File file, String text)

Description

Method for saving the String into a file.

License

Open Source License

Parameter

Parameter Description
file The file which will be saved.
text The content of the file as String.

Return

Returns the success of saving the file.

Declaration

public static boolean save(File file, String text) 

Method Source Code

//package com.java2s;
/*/*w  w  w.j a  v  a2  s.  c  o m*/
 * SWTextEdit
 * Copyright (C) 2006 Philipp Seerainer
 * pisee@users.sourceforge.net
 * http://pisee.sourceforge.net/
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

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

import java.io.FileWriter;
import java.io.IOException;

public class Main {
    /**
     * Method for saving the String into a file.
     * 
     * @param file
     *           The file which will be saved.
     * @param text
     *           The content of the file as String.
     * @return Returns the success of saving the file.
     */
    public static boolean save(File file, String text) {
        try {
            BufferedWriter bw = new BufferedWriter(new FileWriter(file));
            bw.write(text);
            bw.close();
            return true;
        } catch (IOException e) {
            e.printStackTrace();
        }

        return false;
    }
}

Related

  1. save(File file, String content)
  2. save(File pFile, String pString)
  3. save(final String content, final String file)
  4. save(List list, String REPO)
  5. save(Map map, String path)