Java FileInputStream Copy copyFile(File input, File output)

Here you can find the source of copyFile(File input, File output)

Description

Helper function to copy the file.

License

Open Source License

Parameter

Parameter Description
input - The input file.
output - The output file to which the input should be copied.

Exception

Parameter Description
IOException - Any exception thrown during the operation.

Declaration

public static void copyFile(File input, File output) 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  a v a2 s .com*/
     * Helper function to copy the file.
     * 
     * @param input - The input file.
     * @param output - The output file to which the input should be copied.
     * @throws IOException - Any exception thrown during the operation.
     */
    public static void copyFile(File input, File output) throws IOException {
        FileInputStream inputStream = new FileInputStream(input);
        // target file declaration
        FileOutputStream outputStream = new FileOutputStream(output);
        int lengthStream;
        byte[] buff = new byte[1024];
        while ((lengthStream = inputStream.read(buff)) > 0) {
            // writing to the target file contents of the source file
            outputStream.write(buff, 0, lengthStream);
        }
        outputStream.close();
        inputStream.close();
    }
}

Related

  1. copyFile(File in, File out)
  2. copyFile(File in, File out)
  3. copyFile(File in, File out)
  4. copyFile(File inFile, File outFile)
  5. copyFile(File inFile, File outFile)
  6. copyFile(File inputFile, File outputFile)
  7. copyFile(File inputFile, File outputFile)
  8. copyFile(File inputFile, File outputFile)
  9. copyFile(File inputFile, OutputStream os)