Java FileChannel Copy copy2(String sourceFileName, String destFileName)

Here you can find the source of copy2(String sourceFileName, String destFileName)

Description

copy

License

Open Source License

Declaration

public static void copy2(String sourceFileName, String destFileName) throws Exception 

Method Source Code


//package com.java2s;
import java.io.*;
import java.nio.channels.FileChannel;

public class Main {
    private final static int MB = 1048576;

    public static void copy2(String sourceFileName, String destFileName) throws Exception {
        FileInputStream in = new FileInputStream(sourceFileName);
        FileOutputStream out = new FileOutputStream(destFileName);
        FileChannel inC = in.getChannel();
        FileChannel outC = out.getChannel();
        while (inC.position() < inC.size()) {
            inC.transferTo(inC.position(), MB, outC);
            inC.position(inC.position() + MB);
        }/*from  w w  w  .j a va  2s.  co m*/
        inC.close();
        outC.close();
        in.close();
        out.close();
    }
}

Related

  1. copy(String source, String destination)
  2. copy(String source, String destination, boolean recursive)
  3. copy(String sourceFile, String targetFile)
  4. copy0(File src, File dest)
  5. copy12(File file1, File file2)
  6. copyAFile(File source, File target)
  7. copyAll(File source, File targetDir)
  8. copyAndReplace(File from, File to)
  9. copyChannel(ReadableByteChannel in, long length, FileChannel out)