copy File with FileChannel - Java java.nio.channels

Java examples for java.nio.channels:FileChannel

Description

copy File with FileChannel

Demo Code


//package com.java2s;
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 source, File dest) throws IOException {
        FileChannel ic = new FileInputStream(source).getChannel();
        FileChannel oc = new FileOutputStream(dest).getChannel();
        ic.transferTo(0, ic.size(), oc);
        ic.close();/*  w  w  w .j  ava2 s.  co  m*/
        oc.close();
    }
}

Related Tutorials