Java File Copy nio fileCopy(final File dest, final File src)

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

Description

file Copy

License

Open Source License

Declaration

public static void fileCopy(final File dest, final File src) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.File;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

public class Main {
    public static void fileCopy(final File dest, final File src) throws IOException {
        FileInputStream in = null;
        FileOutputStream out = null;
        try {/*from   ww w. j a va2  s. c  o m*/
            in = new FileInputStream(src);
            out = new FileOutputStream(dest);
            FileChannel fcin = in.getChannel();
            FileChannel fcout = out.getChannel();
            long bytes = fcin.size();
            while (bytes > 0L) {
                bytes -= fcout.transferFrom(fcin, 0, bytes);
            }
        } finally {
            if (in != null) {
                in.close();
            }
            if (out != null) {
                out.close();
            }
        }
    }
}

Related

  1. copyToTmpFile(InputStream in, String prefix, String suffix)
  2. fileCopy(File source, File destination)
  3. fileCopy(File source, File target)
  4. fileCopy(File sourceFile, File destFile)
  5. fileCopy(File src, File dest)