Java FileChannel Copy copyFile(String inName, String otName)

Here you can find the source of copyFile(String inName, String otName)

Description

fast file copy utility function

License

Open Source License

Parameter

Parameter Description
inName String name of input file
otName String name of output file

Exception

Parameter Description
Exception an exception

Declaration

static public void copyFile(String inName, String otName)
        throws Exception 

Method Source Code

//package com.java2s;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

public class Main {
    /**//w w w  . j ava  2  s  . c  o  m
     * fast file copy utility function
     * @param inName String name of input file
     * @param otName String name of output file
     * @throws Exception
     */
    static public void copyFile(String inName, String otName)
            throws Exception {
        File inFile = null;
        File otFile = null;
        try {
            inFile = new File(inName);
            otFile = new File(otName);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (inFile == null || otFile == null)
            return;
        FileChannel sourceChannel = new FileInputStream(inFile)
                .getChannel();
        FileChannel destinationChannel = new FileOutputStream(otFile)
                .getChannel();
        sourceChannel.transferTo(0, sourceChannel.size(),
                destinationChannel);
        sourceChannel.close();
        destinationChannel.close();
    }
}

Related

  1. copyFile(String fromFileName, String toFileName)
  2. copyFile(String fromPath, String toPath)
  3. copyFile(String in, String out)
  4. copyFile(String infile, String outfile)
  5. copyFile(String inFile, String outFile)
  6. copyFile(String input, String output)
  7. copyFile(String origPath, String destPath)
  8. copyFile(String source, String destination)
  9. copyFile(String source, String destination)