Java FileChannel Copy copy(final File source, final File dest)

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

Description

copy

License

Open Source License

Declaration

public static void copy(final File source, final 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 {
    public static void copy(final File source, final File dest) throws IOException {
        final FileChannel inChannel = new FileInputStream(source).getChannel();
        final FileChannel outChannel = new FileOutputStream(dest).getChannel();
        try {//  w  w  w. ja va 2s .  c  om
            // magic number for Windows, 64Mb - 32Kb)
            final int maxCount = (64 * 1024 * 1024) - (32 * 1024);
            final long size = inChannel.size();
            long position = 0;
            while (position < size)
                position += inChannel.transferTo(position, maxCount, outChannel);

        } finally {
            if (inChannel != null)
                inChannel.close();
            if (outChannel != null)
                outChannel.close();
        }
    }
}

Related

  1. copy(FileInputStream in, FileOutputStream out)
  2. copy(FileInputStream inputStream, FileOutputStream outputStream)
  3. copy(FileInputStream iStream, FileOutputStream oStream)
  4. copy(final File aCopyFrom, final File aCopyTo)
  5. copy(final File fromFile, final File toFile)
  6. copy(final File src, File dst, final boolean overwrite)
  7. copy(final String aSrcPath, final String aDestPath)
  8. copy(final String aSrcPath, final String aDestPath)
  9. copy(String fromPath, String toPath)