Here you can find the source of copyFile(File src, File dst)
public static void copyFile(File src, File dst)
//package com.java2s; /**//ww w . j a v a 2 s .c om * Copyright (c) 2014 http://www.lushapp.wang * * Licensed under the Apache License, Version 2.0 (the "License"); */ import java.io.*; public class Main { public static void copyFile(File src, File dst) { try { FileInputStream in = null; FileOutputStream out = null; try { out = new FileOutputStream(dst); in = new FileInputStream(src); byte[] buffer = new byte[1024]; int len = 0; while ((len = in.read(buffer)) > 0) { out.write(buffer, 0, len); } } catch (Exception e) { e.printStackTrace(); String dstpath = dst.getAbsolutePath(); if (dstpath.lastIndexOf("/") != -1) { dstpath = dstpath.subSequence(0, dstpath.lastIndexOf("/")).toString(); } else { dstpath = dstpath.subSequence(0, dstpath.lastIndexOf("\\")).toString(); } createDirectory(dstpath); copyFile(src, dst); } finally { if (null != in) { in.close(); } if (null != out) { out.close(); } } } catch (Exception e) { e.printStackTrace(); } } public static void createDirectory(String Directorypath) { File file = new File(Directorypath); if (!file.exists()) { file.mkdir(); file.mkdirs(); } } }