Here you can find the source of copyFile(File input, File output)
Parameter | Description |
---|---|
input | - The input file. |
output | - The output file to which the input should be copied. |
Parameter | Description |
---|---|
IOException | - Any exception thrown during the operation. |
public static void copyFile(File input, File output) throws IOException
//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(); } }