Java FileInputStream Copy copyFile(File sourceFile, File destFile)

Here you can find the source of copyFile(File sourceFile, File destFile)

Description

Copies a file.

License

Open Source License

Parameter

Parameter Description
sourceFile The source file.
destFile The destination file.

Exception

Parameter Description
IOException If an IOException is thrown.

Declaration

public static void copyFile(File sourceFile, File destFile) 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;

public class Main {
    /**//from  w w  w . j  av a2 s .  c  o m
     * Copies a file.
     *
     * @param sourceFile   The source file.
     * @param destFile   The destination file.
     * @throws IOException   If an IOException is thrown.
     */
    public static void copyFile(File sourceFile, File destFile) throws IOException {
        FileOutputStream fos;
        try (FileInputStream fis = new FileInputStream(sourceFile)) {
            fos = new FileOutputStream(destFile);
            fis.getChannel().transferTo(0, sourceFile.length(), fos.getChannel());
        }
        fos.close();
    }
}

Related

  1. copyFile(File source, File target, boolean createParents, FileFilter filter)
  2. copyFile(File source, File target, boolean deleteSourceAfter)
  3. copyFile(File source, File target, boolean replaceIfExists)
  4. copyFile(File sourceDir, File destDir, String filename)
  5. copyFile(File sourceFile, File destDir)
  6. copyFile(File sourceFile, File destFile)
  7. copyFile(File sourceFile, File destFile)
  8. copyFile(File sourceFile, File destFile)
  9. copyFile(File sourceFile, File destFile)