Java File Append Text appendToFile(String filePath, String data)

Here you can find the source of appendToFile(String filePath, String data)

Description

append To File

License

Open Source License

Declaration

public static boolean appendToFile(String filePath, String data) 

Method Source Code


//package com.java2s;
/*/*w w  w.  j  a  va 2s .co m*/
 * JGAAP -- a graphical program for stylometric authorship attribution
 * Copyright (C) 2009,2011 by Patrick Juola
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.BufferedWriter;

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

public class Main {
    public static boolean appendToFile(String filePath, String data) {
        return writeToFile(filePath, data, true);
    }

    private static boolean writeToFile(String filePath, String data, boolean append) {
        BufferedWriter writer;
        try {
            writer = new BufferedWriter(new FileWriter(filePath, append));
            writer.write(data);
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
}

Related

  1. appendToFile(String filename, String str)
  2. appendToFile(String filename, String text)
  3. appendToFile(String fileName, String text)
  4. appendToFile(String filename, String text)
  5. appendToFile(String filePath, String content)
  6. appendToFile(String filepath, String newLine)
  7. appendToFile(String sb, String directory, String fileName)
  8. appendToFile(String str, String filename, boolean appendNewLine)
  9. appendToFile(String string, File file)