Here you can find the source of copyFile(File source, File target)
public static void copyFile(File source, File target) 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 target) throws IOException { InputStream in = null;/*from w ww .j a va 2 s. com*/ OutputStream out = null; try { in = new FileInputStream(source); out = new FileOutputStream(target); while (true) { int data = in.read(); if (data == -1) { break; } out.write(data); } in.close(); out.close(); } finally { if (in != null) { in.close(); } if (out != null) { out.close(); } } } }