Here you can find the source of copyFile(File srcFile, File targetFolder)
public static File copyFile(File srcFile, File targetFolder) throws IOException
//package com.java2s; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class Main { public static File copyFile(File srcFile, File targetFolder) throws IOException { BufferedInputStream bufIn = new BufferedInputStream( new FileInputStream(srcFile)); String targetFilePath = targetFolder.getAbsolutePath() + File.separator + srcFile.getName(); BufferedOutputStream bufOut = new BufferedOutputStream( new FileOutputStream(targetFilePath)); byte[] buf = new byte[1024]; int cnt = 0; while ((cnt = bufIn.read(buf)) != -1) { bufOut.write(buf, 0, cnt);/*from w ww . j ava 2 s . c o m*/ } bufOut.close(); bufIn.close(); return new File(targetFilePath); } }