Java FileChannel Copy copyFile(File in, File out)

Here you can find the source of copyFile(File in, File out)

Description

Kopieert een file, NIO

License

Open Source License

Exception

Parameter Description
IOException an exception

Declaration

public static void copyFile(File in, File out) 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 {
    /**/*from  w ww .j a  va  2  s  .c o m*/
     * Kopieert een file, NIO
     *
     * @throws IOException
     */
    public static void copyFile(File in, File out) throws IOException {
        try (FileInputStream fin = new FileInputStream(in);
                FileChannel inChannel = fin.getChannel();
                FileOutputStream fout = new FileOutputStream(out);
                FileChannel outChannel = fout.getChannel()) {
            // fix copy bestanden groter dan 64MB (zie link)
            // // magic number for Windows, 64Mb - 32Kb)
            // int maxCount = (64 * 1024 * 1024) - (32 * 1024);
            // long size = inChannel.size();
            // long position = 0;
            // while (position < size) {
            // position +=
            // inChannel.transferTo(position, maxCount, outChannel);
            inChannel.transferTo(0, inChannel.size(), outChannel);
        } catch (IOException e) {
            throw e;
        }
    }
}

Related

  1. copyFile(File in, File out)
  2. copyFile(File in, File out)
  3. copyFile(File in, File out)
  4. copyFile(File in, File out)
  5. copyFile(File in, File out)
  6. copyfile(File infile, File outfile)
  7. copyFile(File inFile, File outFile)
  8. copyFile(File inputFile, File outputFile)
  9. copyFile(File source, File dest)