Java FileChannel Copy copyFile(File from, File to)

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

Description

copy File

License

Apache License

Declaration

public static File copyFile(File from, File to) 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 File copyFile(File from, File to) throws IOException {
        FileChannel inChannel = new FileInputStream(from).getChannel();
        FileChannel outChannel = new FileOutputStream(to).getChannel();
        try {//from   w  ww.j  ava  2  s  .  c om
            inChannel.transferTo(0, inChannel.size(), outChannel);
        } catch (IOException e) {
            throw e;
        } finally {
            if (inChannel != null)
                inChannel.close();
            if (outChannel != null)
                outChannel.close();

        }
        return to;
    }
}

Related

  1. copyFile(File aFromFile, String aToFilename)
  2. copyFile(File copyFrom, File copyTo)
  3. copyFile(File file, String destDir)
  4. copyFile(File fileIn, File fileOut)
  5. copyFile(File from, File to)
  6. copyFile(File from, File to)
  7. copyFile(File from, File to)
  8. copyFile(File from, File to, long fromoffset, long tooffset, long size)
  9. copyFile(File in, File out)