Here you can find the source of copyFile(final File oldfile, final File newfile)
public static boolean copyFile(final File oldfile, final File newfile)
//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 boolean copyFile(final File oldfile, final File newfile) { FileInputStream fis;//from ww w . j a v a 2 s .c om FileOutputStream fos; int len; byte[] buf; try { if (!newfile.exists()) { newfile.createNewFile(); } if (!oldfile.canRead() || !newfile.canWrite()) { return false; } fis = new FileInputStream(oldfile); fos = new FileOutputStream(newfile); buf = new byte[4096]; while ((len = fis.read(buf)) > 0) { fos.write(buf, 0, len); } fis.close(); fos.close(); } catch (final IOException e) { e.printStackTrace(); } return true; } }