Java BufferedReader Copy copyFileWithAppend(File source, File destination)

Here you can find the source of copyFileWithAppend(File source, File destination)

Description

copy File With Append

License

Open Source License

Declaration

private static void copyFileWithAppend(File source, File destination) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class Main {
    private static void copyFileWithAppend(File source, File destination) throws IOException {
        if (!destination.exists()) {
            destination.getParentFile().mkdirs();
            destination.createNewFile();
        }// w ww .ja v a2s  . c o m
        if (!source.exists()) {
            throw new IOException("Source file must exist!");
        }
        BufferedReader sourceReader = new BufferedReader(new FileReader(source));
        BufferedWriter destinationWriter = new BufferedWriter(new FileWriter(destination, true));
        String line;
        while ((line = sourceReader.readLine()) != null) {
            destinationWriter.write(line);
            destinationWriter.newLine();
        }
        destinationWriter.flush();
        destinationWriter.close();
        sourceReader.close();
    }
}

Related

  1. copyFileContentsIntoAnotherFile(String inputFileName, PrintWriter Out)
  2. copyFileFromJar(File jarFile, File targetFile, String sourceFilePath)
  3. copyFileLinewise(File inputFile, File outputFile)
  4. copyFileRecursivlyLinewise(File inDir, File outDir)
  5. copyFileTextMode(String source, String destination)