Java FileChannel Copy copyFile(String source, String destination)

Here you can find the source of copyFile(String source, String destination)

Description

copy File

License

Open Source License

Declaration

public static void copyFile(String source, String 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 copyFile(String source, String destination) throws IOException {
        File sourceFile = new File(source);
        File destinationFile = new File(destination);
        copyFile(sourceFile, destinationFile);
    }//from w  w  w.  j a  v a2 s.co  m

    public static void copyFile(File source, File destination) throws IOException {
        FileChannel in = null;
        FileChannel out = null;
        try {
            in = new FileInputStream(source).getChannel();
            out = new FileOutputStream(destination).getChannel();
            in.transferTo(0, in.size(), out);
        } finally {
            if (in != null) {
                in.close();
            }
            if (out != null) {
                out.close();
            }
        }
    }
}

Related

  1. copyFile(String infile, String outfile)
  2. copyFile(String inFile, String outFile)
  3. copyFile(String inName, String otName)
  4. copyFile(String input, String output)
  5. copyFile(String origPath, String destPath)
  6. copyFile(String source, String destination)
  7. copyFile(String source, String destination)
  8. copyFile(String source, String target)
  9. copyFile(String source, String target)