Java FileChannel Copy copyFile(String inFile, String outFile)

Here you can find the source of copyFile(String inFile, String outFile)

Description

copy File

License

Open Source License

Declaration

public static void copyFile(String inFile, String outFile) 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 {
    public static void copyFile(String inFile, String outFile) throws IOException {

        File in = new File(inFile);
        File out = new File(outFile);
        FileChannel inChannel = null;
        FileChannel outChannel = null;
        try {//from w w w  . j  ava  2s . c  o m
            inChannel = new FileInputStream(in).getChannel();
            outChannel = new FileOutputStream(out).getChannel();
            inChannel.transferTo(0, inChannel.size(), outChannel);
        } catch (IOException e) {
            throw e;
        } finally {
            if (inChannel != null)
                inChannel.close();
            if (outChannel != null)
                outChannel.close();
        }
    }
}

Related

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