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

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

Description

copy

License

Open Source License

Declaration

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

Method Source Code

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

import java.io.*;

import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

public class Main {
    public static void copy(File source, File dest) throws IOException {
        FileChannel in = null, out = null;
        try {//from ww w  .  ja va 2  s.  co m
            in = new FileInputStream(source).getChannel();
            out = new FileOutputStream(dest).getChannel();

            long size = in.size();
            MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0,
                    size);
            out.write(buf);
        } finally {
            if (in != null)
                in.close();
            if (out != null)
                out.close();
        }
    }
}

Related

  1. copy(File input, File output)
  2. copy(File inputFile, OutputStream out)
  3. copy(File source, File dest)
  4. copy(File source, File dest)
  5. copy(File source, File dest)
  6. copy(File source, File dest)
  7. copy(File source, File dest, boolean preserveTime)
  8. copy(File source, File destination)
  9. copy(File source, File destination)