Here you can find the source of copyFile(File existingFile, File destFile)
public static void copyFile(File existingFile, File destFile)
//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 { public static void copyFile(File existingFile, File destFile) { FileInputStream source = null; FileOutputStream destination = null; byte[] buffer; int bytes_read; try {/* w ww . j a va 2s . c o m*/ // If we've gotten this far, then everything is okay; we can // copy the file. source = new FileInputStream(existingFile); destination = new FileOutputStream(destFile); buffer = new byte[1024]; while (true) { bytes_read = source.read(buffer); if (bytes_read == -1) break; destination.write(buffer, 0, bytes_read); } } catch (Exception e) { e.printStackTrace(); } finally { if (source != null) { try { source.close(); } catch (IOException e) { ; } } if (destination != null) { try { destination.close(); } catch (IOException e) { ; } } } } }