Java File Append appendFile(File targetFile, String text)

Here you can find the source of appendFile(File targetFile, String text)

Description

Appends the given String to the end of a file.

License

Apache License

Parameter

Parameter Description
targetFile the file to append the data String to
text some String

Exception

Parameter Description
IOException if an error occurred while appending the data

Declaration

public static void appendFile(File targetFile, String text) throws IOException 

Method Source Code


//package com.java2s;
/*//  ww w.  j  a  va 2s  .  co  m
 * Copyright (C) 2007 Roland Krueger
 * 
 * Created on 26.03.2010
 * 
 * Author: Roland Krueger (www.rolandkrueger.info)
 * 
 * This file is part of RoKlib.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

import java.io.BufferedWriter;
import java.io.File;

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

public class Main {
    /**
     * Appends the given String to the end of a file.
     * 
     * @param targetFile
     *          the file to append the data String to
     * @param text
     *          some String
     * @throws IOException
     *           if an error occurred while appending the data
     */
    public static void appendFile(File targetFile, String text) throws IOException {
        BufferedWriter writer = new BufferedWriter(new FileWriter(targetFile));
        writer.append(text);
        writer.flush();
        writer.close();
    }
}

Related

  1. appendFile(File f, StringBuffer sb)
  2. appendFile(File file, String content)
  3. appendFile(File file, String url)
  4. appendFile(File filename, String data)
  5. appendFile(File src, File dst)
  6. appendFile(File targetFile, String toWrite)
  7. appendFile(final File srcFile, final File destFile)
  8. appendFile(final String filename, final String content)
  9. appendFile(final String name, final String s)