Java File Copy nio copy(File from, File to)

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

Description

copy

License

Open Source License

Declaration

public static void copy(File from, File to) throws MalformedURLException, IOException 

Method Source Code


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

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;

public class Main {
    public static void copy(File from, File to) throws MalformedURLException, IOException {
        copy(from.toURI().toURL(), to);/*from  ww  w .  j a  v  a 2  s  .com*/
    }

    public static void copy(URL from, File to) throws MalformedURLException, IOException {
        if (!to.exists()) {
            ReadableByteChannel rbc;
            rbc = Channels.newChannel(from.openStream());
            FileOutputStream fos = new FileOutputStream(to);
            fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
        }
    }
}

Related

  1. copy(File a, File b)
  2. copy(File base_path, File in, File out)
  3. copy(File copied, File destination)
  4. copy(File file, File toDirectory)
  5. copy(File from, File to)
  6. copy(File from, File to)
  7. copy(File from, File to, final boolean recursive, Function excluded)
  8. copy(File in, File out)