Java BufferedInputStream Copy copyFile(final File source, final File dest, final boolean overwrite)

Here you can find the source of copyFile(final File source, final File dest, final boolean overwrite)

Description

copy File

License

Apache License

Declaration

public static void copyFile(final File source, final File dest, final boolean overwrite)
            throws IOException, FileNotFoundException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import java.io.IOException;

public class Main {
    public static void copyFile(final File source, final File dest, final boolean overwrite)
            throws IOException, FileNotFoundException {
        if (dest.exists()) {
            if (overwrite)
                dest.delete();//from ww w .  j  ava  2  s  . co  m
            else
                return;
        }

        if (!dest.getParentFile().exists())
            dest.getParentFile().mkdirs();

        BufferedInputStream in = new BufferedInputStream(new FileInputStream(source));
        ;
        BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(dest, true));
        ;

        int bytes = 0;
        while ((bytes = in.read()) != -1) {
            out.write(bytes);
        }
        in.close();
        out.close();
    }
}

Related

  1. copyFile(File srcFile, File destFile, boolean createCopy)
  2. copyFile(File srcFile, File detFolder)
  3. copyFile(File srcFile, File targetFolder)
  4. copyFile(final File from, final File to)
  5. copyFile(final File fSource, final File fDest)
  6. copyFile(final File source, final File destination)
  7. copyFile(final File source, final File destination, final boolean overwrite)
  8. copyFile(final File sourceFile, final File targetFile)
  9. copyFile(final File src, final File dest)