Java FileChannel Copy copyFileUsingFileChannels(File source, File dest)

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

Description

copy File Using File Channels

License

Open Source License

Parameter

Parameter Description
source a parameter
dest a parameter

Exception

Parameter Description
IOException an exception

Declaration

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

Method Source Code

//package com.java2s;

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

import java.nio.channels.FileChannel;

public class Main {
    /**//  w ww.  j  av  a2s .c o m
     * @param source
     * @param dest
     * @throws IOException
     */
    public static void copyFileUsingFileChannels(File source, File dest) throws IOException {
        FileChannel inputChannel = null;
        FileChannel outputChannel = null;
        try {
            inputChannel = new FileInputStream(source).getChannel();
            outputChannel = new FileOutputStream(dest).getChannel();
            outputChannel.transferFrom(inputChannel, 0, inputChannel.size());
        } catch (Exception e) {
            e.printStackTrace();
            e.printStackTrace(System.out);
        } finally {
            if (inputChannel != null)
                inputChannel.close();
            if (outputChannel != null)
                outputChannel.close();
        }
    }
}

Related

  1. copyFileToStream(File in, OutputStream out)
  2. copyFileUsingChannel(File source, File dest)
  3. copyFileUsingChannel(File source, File dest)
  4. copyFileUsingFileChannels(File source, File dest)
  5. copyFileUsingFileChannels(File source, File dest)
  6. copyFolder(File fin, File fout)
  7. copyFromZip(ZipFile zipFile, String locationInBundle, File destination)
  8. copyInternal(FileInputStream in, FileOutputStream out)
  9. copyLarge(FileInputStream in, FileOutputStream out)