Java FileChannel Copy copyFile(File src, File dst)

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

Description

copy File

License

Apache License

Declaration

public static void copyFile(File src, File dst) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache 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 copyFile(File src, File dst) throws IOException {
        long p = 0, dp, size;
        FileChannel in = null, out = null;

        try {/*www.  java  2  s . c  o  m*/
            if (!dst.exists())
                dst.createNewFile();

            in = new FileInputStream(src).getChannel();
            out = new FileOutputStream(dst).getChannel();
            size = in.size();

            while ((dp = out.transferFrom(in, p, size)) > 0) {
                p += dp;
            }
        } finally {
            try {
                if (out != null)
                    out.close();
            } finally {
                if (in != null)
                    in.close();
            }
        }
    }
}

Related

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