Java FileChannel Copy copyFile(File source, File dest)

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

Description

copy File

License

Open Source License

Declaration

public static void copyFile(File source, File dest) throws IOException 

Method Source Code

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

import java.io.*;

import java.nio.channels.FileChannel;

public class Main {
    public static void copyFile(File source, File dest) throws IOException {

        if (!source.exists())
            return;
        if (!dest.exists()) {
            dest.getParentFile().mkdirs();
            dest.createNewFile();//from ww  w . ja va 2  s .  c o m
        }

        FileChannel srcChannel = new FileInputStream(source).getChannel();
        FileChannel dstChannel = new FileOutputStream(dest).getChannel();
        dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
        srcChannel.close();
        dstChannel.close();

    }
}

Related

  1. copyfile(File infile, File outfile)
  2. copyFile(File inFile, File outFile)
  3. copyFile(File inputFile, File outputFile)
  4. copyFile(File source, File dest)
  5. copyFile(File source, File dest)
  6. copyFile(File source, File destination)
  7. copyFile(File source, File destination)
  8. copyFile(File source, File destination)
  9. copyFile(File source, File destination)