Java FileInputStream Copy copyFile(String sourceFile, String destFile)

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

Description

copyFile (source,dest) copies the file from one location to another one

License

Open Source License

Parameter

Parameter Description
sourceFile file to be copied
destFile copy location

Exception

Parameter Description
IOException file not found, copy error

Declaration

public static void copyFile(String sourceFile, String destFile) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Main {
    /**//from   w ww. j  a  v a  2s .c  om
     * <code>copyFile (source,dest)</code> copies the file from one location to another one
     * @param sourceFile   file to be copied
     * @param destFile   copy location
     * @throws IOException file not found, copy error
     */
    public static void copyFile(String sourceFile, String destFile) throws IOException {
        InputStream in = new FileInputStream(sourceFile);
        OutputStream out = new FileOutputStream(destFile);

        byte[] buffer = new byte[1024];

        int length;
        //copy the file content in bytes
        while ((length = in.read(buffer)) > 0) {
            out.write(buffer, 0, length);
        }
        in.close();
        out.close();
    }
}

Related

  1. copyFile(String source, String destination)
  2. copyFile(String source, String destination)
  3. copyFile(String source, String target)
  4. copyFile(String source, String targetDirectory, String filesep)
  5. copyFile(String sourceFile, String destDir, String newFileName)
  6. copyFile(String sourcefile, String targetfile)
  7. copyFile(String sourcefile, String targetFile)
  8. copyFile(String sourceFile, String targetFile)
  9. copyFile(String sourceFile, String targetFolder)