Java Write String to File writeFile(File file, String dataString)

Here you can find the source of writeFile(File file, String dataString)

Description

Writes a string to a file;

License

Open Source License

Parameter

Parameter Description
file a parameter
dataString a parameter

Declaration

public static boolean writeFile(File file, String dataString) 

Method Source Code

//package com.java2s;
/**//w  w  w .  j  a va  2 s  . c om
    
   BlackBoard BreadBoard Designer
   Written and maintained by Matthias Pueski 
       
   Copyright (c) 2010-2011 Matthias Pueski
       
   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;

import java.io.PrintWriter;

public class Main {
    /**
     * Writes a string to a file;
     * 
     * @param file
     * @param dataString
     * @return
     */
    public static boolean writeFile(File file, String dataString) {
        try {
            PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file)));
            out.print(dataString);
            out.flush();
            out.close();
        } catch (IOException e) {
            return false;
        }
        return true;
    }
}

Related

  1. writeFile(File file, String contents)
  2. writeFile(File file, String data)
  3. writeFile(File file, String data)
  4. writeFile(File file, String data)
  5. writeFile(File file, String data, boolean append)
  6. writeFile(File file, String text)
  7. writeFile(File file, String text)
  8. writeFile(File file, String... lines)
  9. writeFile(File file, String... lines)