Java FileChannel Copy copyFile(File src, File dest)

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

Description

copy File

License

Open Source License

Declaration

@SuppressWarnings("resource")
    public static void copyFile(File src, File dest) throws IOException 

Method Source Code

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

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

import java.io.IOException;

import java.nio.channels.FileChannel;

public class Main {
    @SuppressWarnings("resource")
    public static void copyFile(File src, File dest) throws IOException {
        FileChannel inChannel = new FileInputStream(src).getChannel();
        FileChannel outChannel = new FileOutputStream(dest).getChannel();

        int maxCount = (64 * 1024 * 1024) - (32 * 1024);
        long size = inChannel.size();
        long position = 0;
        while (position < size) {
            position += inChannel.transferTo(position, maxCount, outChannel);
        }/*  w  ww  .  j  a v a  2s  .c  o  m*/

        if (inChannel != null)
            inChannel.close();

        if (outChannel != null)
            outChannel.close();

        dest.setLastModified(src.lastModified());
    }
}

Related

  1. copyFile(File sourceFile, File targetFile)
  2. copyFile(File sourceFile, File targetFile)
  3. copyFile(File sourceFile, File targetFile)
  4. copyFile(File src, File dest)
  5. copyFile(File src, File dest)
  6. copyFile(File src, File dest)
  7. copyFile(File src, File destination)
  8. copyFile(File src, File destination)
  9. copyFile(File src, File dst)