Here you can find the source of copyFile(File srcFile, File destFile)
public static void copyFile(File srcFile, File destFile) 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 srcFile, File destFile) throws IOException { FileOutputStream fos = new FileOutputStream(destFile); try {//from w w w . j a v a2 s. co m copyToOutputStream(srcFile, fos); } finally { fos.close(); } } public static void copyToOutputStream(File file, OutputStream outputStream) throws IOException { InputStream is = new FileInputStream(file); try { copyToOutputStream(is, outputStream); } finally { is.close(); } } public static void copyToOutputStream(InputStream is, OutputStream os) throws IOException { byte[] buffer = new byte[32768]; while (true) { int bytesRead = is.read(buffer); if (bytesRead == -1) { break; } os.write(buffer, 0, bytesRead); } } }