Java File Copy nio copy(File source, File destination)

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

Description

copy

License

Open Source License

Declaration

public static void copy(File source, File destination) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source 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 copy(File source, File destination) throws IOException {
        try {// ww w .j  a  va 2  s.c  om
            FileChannel sourceChannel = new FileInputStream(source.getPath()).getChannel();
            FileChannel destinationChannel = new FileOutputStream(destination.getPath()).getChannel();
            destinationChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
            sourceChannel.close();
            destinationChannel.close();
        } catch (Exception e) {
            System.err.println("Couldn't close sources or write");
        }
    }
}

Related

  1. copy(File source, File dest)
  2. copy(File source, File dest)
  3. copy(File source, File dest, boolean preserveTime)
  4. copy(File source, File destination)
  5. copy(File source, File destination)
  6. copy(File source, File destination)
  7. copy(File source, File destination)
  8. copy(File source, File destination)
  9. copy(File source, File target)