Java File Append Text appendToFile(final String text, final String urlFile)

Here you can find the source of appendToFile(final String text, final String urlFile)

Description

Append the specified text at the end of the File.

License

Open Source License

Parameter

Parameter Description
text The text to append to the file.
urlFile The url file.

Exception

Parameter Description
IOException if the file does not exist or cannot be read.

Declaration

public static void appendToFile(final String text, final String urlFile) throws IOException 

Method Source Code

//package com.java2s;
/*//from w w w. j a va2 s.c o  m
 *    Geotoolkit - An Open Source Java GIS Toolkit
 *    http://www.geotoolkit.org
 *
 *    (C) 2008 - 2009, Geomatys
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation; either
 *    version 2.1 of the License, or (at your option) any later version.
 *
 *    This library 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
 *    Lesser General Public License for more details.
 */

import java.io.BufferedWriter;

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

public class Main {
    /**
     * Append the specified text at the end of the File.
     *
     * @param text The text to append to the file.
     * @param urlFile The url file.
     *
     * @throws IOException if the file does not exist or cannot be read.
     */
    public static void appendToFile(final String text, final String urlFile) throws IOException {

        //true means we append a the end of the file
        final FileWriter fw = new FileWriter(urlFile, true);
        final BufferedWriter output = new BufferedWriter(fw);

        try {
            output.write(text);
            output.newLine();
            output.flush();
        } finally {
            output.close();
        }
    }
}

Related

  1. appendToFile(File destFile, InputStream source)
  2. appendToFile(File file, String data)
  3. appendToFile(File tempFile, String str)
  4. appendToFile(final File file, final String contents)
  5. appendToFile(final String filePath, final String textToAppend)
  6. appendToFile(float[] in, String filename)
  7. appendToFile(IFile file, String output)
  8. appendToFile(List strList, File file)
  9. appendToFile(String baseFilename, String appendingFilename)