Here you can find the source of copyFile(File src, File dst)
public static boolean copyFile(File src, File dst)
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { public static boolean copyFile(File src, File dst) { if (!src.exists()) { return false; }// ww w .ja v a 2 s.c o m if (!dst.getParentFile().exists()) { dst.getParentFile().mkdirs(); } else { if (dst.exists()) { dst.delete(); } } try { dst.createNewFile(); } catch (IOException e) { e.printStackTrace(); return false; } BufferedInputStream in = null; BufferedOutputStream out = null; try { in = new BufferedInputStream(new FileInputStream(src)); out = new BufferedOutputStream(new FileOutputStream(dst)); byte[] buffer = new byte[1024 * 4]; int len; while ((len = in.read(buffer)) != -1) { out.write(buffer, 0, len); } out.flush(); } catch (FileNotFoundException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { } } if (out != null) { try { out.close(); } catch (IOException e) { } } } return true; } }