Java Text File Write writeStringToFile(String file, String data, boolean append)

Here you can find the source of writeStringToFile(String file, String data, boolean append)

Description

Write string to file.

License

Open Source License

Parameter

Parameter Description
file the file
data the data
append the append

Declaration

public static void writeStringToFile(String file, String data, boolean append) 

Method Source Code

//package com.java2s;
/*/*from   w  ww.j ava  2  s.c  om*/
This file is part of PSFj.
    
PSFj 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 3 of the License, or
(at your option) any later version.
    
PSFj 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 PSFj.  If not, see <http://www.gnu.org/licenses/>. 
    
   Copyright 2013,2014 Cyril MONGIS, Patrick Theer, Michael Knop
       
 */

import java.io.BufferedWriter;

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

public class Main {
    /**
     * Write string to file.
     *
     * @param file the file
     * @param data the data
     * @param append the append
     */
    public static void writeStringToFile(String file, String data, boolean append) {
        FileWriter fstream;
        try {
            fstream = new FileWriter(file, append);
            BufferedWriter out = new BufferedWriter(fstream);
            out.write(data);
            out.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
}

Related

  1. writeStringToFile(String contents, String path)
  2. writeStringToFile(String contents, String path, String encoding)
  3. writeStringToFile(String data, String filename, boolean append)
  4. writeStringToFile(String data, String filepath)
  5. writeStringToFile(String f, String s, boolean append)
  6. writeStringToFile(String file, String str, boolean append, boolean newLine)
  7. writeStringToFile(String fileName, String content)
  8. writeStringToFile(String filename, String content)
  9. writeStringToFile(String fileName, String src)