Java File Append appendFile(File src, File dst)

Here you can find the source of appendFile(File src, File dst)

Description

append File

License

Open Source License

Declaration

public static void appendFile(File src, File dst) throws IOException 

Method Source Code


//package com.java2s;
/*/*from ww  w .j ava2  s  .c  o m*/
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2006-2010 Sun Microsystems, Inc.
 *      Portions Copyright 2011-2015 ForgeRock AS
 *      Portions Copyright 2013 Manuel Gaupp
 */

import java.io.*;

public class Main {
    public static void appendFile(File src, File dst) throws IOException {
        copyOrAppend(src, dst, true);
    }

    private static void copyOrAppend(File src, File dst, boolean append) throws IOException {
        try (InputStream in = new FileInputStream(src); OutputStream out = new FileOutputStream(dst, append)) {
            // Transfer bytes from in to out
            byte[] buf = new byte[8192];
            int len;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
        }
    }
}

Related

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