Java File Append Text appendToTextFile(final File file, final String text)

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

Description

Writes the buffer to a Matlab file

License

Open Source License

Parameter

Parameter Description
file a parameter
buffer a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static void appendToTextFile(final File file, final String text) throws IOException 

Method Source Code


//package com.java2s;
/*/*  w  w w .j av a 2s  .  c o m*/
       
This file is part of the Xapagy Cognitive Architecture 
Copyright (C) 2008-2017 Ladislau Boloni
    
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.File;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;

public class Main {
    /**
     * Writes the buffer to a Matlab file
     * 
     * @param file
     * @param buffer
     * @throws IOException
     */
    public static void appendToTextFile(final File file, final String text) throws IOException {
        try (FileOutputStream out = new FileOutputStream(file, true); PrintWriter pw = new PrintWriter(out);) {
            pw.write(text);
            pw.flush();
            pw.close();
            out.close();
        }
    }
}

Related

  1. appendToFile(String sb, String directory, String fileName)
  2. appendToFile(String str, String filename, boolean appendNewLine)
  3. appendToFile(String string, File file)
  4. appendToFile(String text, String fileName)
  5. appendToString(final byte b, final Appendable ap)
  6. appendToTextFile(String contents, String fullPathFilename)