Here you can find the source of copyFile(String srcPath, String destPath)
public static boolean copyFile(String srcPath, String destPath)
//package com.java2s; //License from project: Open Source License import java.io.*; import java.nio.channels.FileChannel; public class Main { /**/*from w ww. j a va 2 s. c om*/ * @return true if copy succeed. */ public static boolean copyFile(String srcPath, String destPath) { boolean success = false; FileChannel srcChannel = null; FileChannel destChannel = null; try { File dest = new File(destPath); if (dest.exists()) dest.createNewFile(); srcChannel = new FileInputStream(srcPath).getChannel(); destChannel = new FileOutputStream(destPath).getChannel(); srcChannel.transferTo(0, srcChannel.size(), destChannel); success = true; } catch (IOException e) { e.printStackTrace(); success = false; } finally { try { if (srcChannel != null) srcChannel.close(); if (destChannel != null) destChannel.close(); } catch (IOException e) { e.printStackTrace(); } } return success; } }