Java File Copy nio copy(File src, File dist)

Here you can find the source of copy(File src, File dist)

Description

copy

License

Open Source License

Declaration

public static boolean copy(File src, File dist) 

Method Source Code

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

import java.io.Closeable;
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 boolean copy(File src, File dist) {

        FileInputStream fis = null;
        FileChannel in = null;//from   w w w  .  j a v a2 s .  com
        FileOutputStream fos = null;
        FileChannel out = null;
        try {

            fis = new FileInputStream(src);
            in = fis.getChannel();
            fos = new FileOutputStream(dist);
            out = fos.getChannel();

            in.transferTo(0, in.size(), out);

            return true;

        } catch (IOException e) {

            return false;

        } finally {
            close(in, fis, out, fos);
        }

    }

    public static void close(Closeable... closeables) {

        for (Closeable c : closeables)
            try {
                c.close();
            } catch (IOException e) {
                /* ignore */ }

    }
}

Related

  1. copy(File sourceFile, File targetFile)
  2. copy(File src, File dest)
  3. copy(File src, File dest)
  4. copy(File src, File dest)
  5. copy(File src, File dest)
  6. copy(File src, File dst)
  7. copy(File src, File dst)
  8. copy(File src, File dst)
  9. copy(File src, File dst)