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) 

Method Source Code

//package com.java2s;

import java.io.FileInputStream;
import java.io.FileOutputStream;

import java.nio.channels.FileChannel;

public class Main {
    public static void copyFile(String infile, String outfile) {
        try {/*w ww  . j  a  v a2 s .c om*/
            FileInputStream fin = new FileInputStream(infile);
            FileOutputStream fout = new FileOutputStream(outfile);

            FileChannel fcin = fin.getChannel();
            FileChannel fcout = fout.getChannel();

            try {
                fcout.transferFrom(fcin, 0, fcin.size());
            } finally {
                fcout.close();
                fout.close();
            }
        } catch (Exception e) {

            e.printStackTrace();
        }

    }
}

Related

  1. copyFile(java.io.File in, java.io.File out)
  2. copyFile(Path source, Path target)
  3. copyFile(String fromFileName, String toFileName)
  4. copyFile(String fromPath, String toPath)
  5. copyFile(String in, String out)
  6. copyFile(String inFile, String outFile)
  7. copyFile(String inName, String otName)
  8. copyFile(String input, String output)
  9. copyFile(String origPath, String destPath)