Here you can find the source of copyFile(File aFromFile, String aToFilename)
public static void copyFile(File aFromFile, String aToFilename) throws IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.channels.FileChannel; public class Main { public static void copyFile(File aFromFile, String aToFilename) throws IOException { File outdir = getFileDirOnly(new File(aToFilename)); outdir.mkdirs();//from w w w . j a v a 2s. c om FileInputStream fis = new FileInputStream(aFromFile.getAbsolutePath()); FileChannel inChannel = fis.getChannel(); FileOutputStream fos = new FileOutputStream(aToFilename); FileChannel outChannel = fos.getChannel(); try { inChannel.transferTo(0, inChannel.size(), outChannel); } catch (IOException e) { throw e; } finally { if (fis != null) fis.close(); if (fos != null) fos.close(); if (inChannel != null) inChannel.close(); if (outChannel != null) outChannel.close(); } } public static File getFileDirOnly(File aFile) { if (aFile != null) { String s1 = aFile.getPath(); String s2 = aFile.getName(); return new File(s1.substring(0, s1.length() - s2.length())); } else { return null; } } }