Java FileChannel Copy copyFile(File sourceFile, File destFile)

Here you can find the source of copyFile(File sourceFile, File destFile)

Description

copy File

License

Open Source License

Declaration

public static void copyFile(File sourceFile, File destFile) 

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(File sourceFile, File destFile) {
        FileInputStream in = null;
        FileOutputStream out = null;
        FileChannel source = null;
        FileChannel destination = null;

        try {//from w w w .j a va  2 s.c o m
            destFile.createNewFile();

            in = new FileInputStream(sourceFile);
            out = new FileOutputStream(destFile);
            source = in.getChannel();
            destination = out.getChannel();
            destination.transferFrom(source, 0, source.size());

        } catch (IOException e) {
            e.printStackTrace();

        } finally {
            try {
                if (source != null)
                    source.close();
                if (destination != null)
                    destination.close();
                if (in != null)
                    in.close();
                if (out != null)
                    out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

Related

  1. copyFile(File source, File target)
  2. copyFile(File source, File target)
  3. copyFile(File source, File target)
  4. copyFile(File source, File target)
  5. copyFile(File source, File target)
  6. copyFile(File sourceFile, File destFile)
  7. copyFile(File sourceFile, File destFile)
  8. copyFile(File sourceFile, File destFile)
  9. copyFile(File sourceFile, File destFile)