Java FileChannel Copy copyFileUsingChannel(File source, File dest)

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

Description

copy File Using Channel

License

Apache License

Declaration

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

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.*;
import java.nio.channels.FileChannel;

public class Main {
    public static void copyFileUsingChannel(File source, File dest) throws IOException {
        FileChannel sourceChannel = null;
        FileChannel destChannel = null;
        try {/*from w w w  . j av  a2  s  . c om*/
            sourceChannel = new FileInputStream(source).getChannel();
            destChannel = new FileInputStream(dest).getChannel();
            sourceChannel.transferTo(0, sourceChannel.size(), destChannel);
        } finally {
            sourceChannel.close();
            destChannel.close();
        }
    }
}

Related

  1. copyFiles(final File fromFile, final File toFile)
  2. copyFileToDir(File file, File destDir)
  3. copyFileToDirectory(String fileFrom, String destinationDirectory)
  4. copyFileToFolder(final String resultFile, final String targetPath)
  5. copyFileToStream(File in, OutputStream out)
  6. copyFileUsingChannel(File source, File dest)
  7. copyFileUsingFileChannels(File source, File dest)
  8. copyFileUsingFileChannels(File source, File dest)
  9. copyFileUsingFileChannels(File source, File dest)