Java FileChannel Copy copyFile(File source, File destination)

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

Description

Copies single file to new location borrowed from: http://www.crazysquirrel.com/computing/java/basics/java-file-and-directory-copying.jspx

License

Open Source License

Parameter

Parameter Description
source a parameter
destination a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static final void copyFile(File source, File destination) 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 {
    /** Copies single file to new location
     * borrowed from: http://www.crazysquirrel.com/computing/java/basics/java-file-and-directory-copying.jspx
     * @param source/*www  .  ja v  a2s .  co  m*/
     * @param destination
     * @throws IOException
     */
    public static final void copyFile(File source, File destination) throws IOException {
        FileChannel sourceChannel = new FileInputStream(source).getChannel();
        FileChannel targetChannel = new FileOutputStream(destination).getChannel();
        sourceChannel.transferTo(0, sourceChannel.size(), targetChannel);
        sourceChannel.close();
        targetChannel.close();
    }
}

Related

  1. copyFile(File source, File dest)
  2. copyFile(File source, File destination)
  3. copyFile(File source, File destination)
  4. copyFile(File source, File destination)
  5. copyFile(File source, File destination)
  6. copyFile(File source, File destination)
  7. copyFile(File source, File destination)
  8. copyFile(File source, File destination, boolean overwrite)
  9. copyFile(File source, File destination, long chunkSize, boolean overwrite)