Here you can find the source of copyFile(File source, File destination)
public static void copyFile(File source, File destination) 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; import java.io.InputStream; import java.io.OutputStream; public class Main { public static void copyFile(File source, File destination) throws IOException { ///*from ww w . j a va 2s. c o m*/ // if the destination is a dir, what we really want to do is create // a file with the same name in that dir // if (destination.isDirectory()) destination = new File(destination, source.getName()); FileInputStream input = new FileInputStream(source); copyFile(input, destination); } public static void copyFile(InputStream input, File destination) throws IOException { OutputStream output = null; output = new FileOutputStream(destination); byte[] buffer = new byte[1024]; int bytesRead = input.read(buffer); while (bytesRead >= 0) { output.write(buffer, 0, bytesRead); bytesRead = input.read(buffer); } input.close(); output.close(); } }