Here you can find the source of copyFile(File src, File dest)
public static void copyFile(File src, File dest) 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; public class Main { public static void copyFile(File src, File dest) throws IOException { byte[] bytes = readFile(src); createFile(bytes, dest);//from w w w .ja v a 2 s. c o m } public static byte[] readFile(File file) throws IOException { int length = (int) file.length(); FileInputStream fis = new FileInputStream(file); byte[] result = new byte[length]; int pos = 0; while (pos < length) { pos += fis.read(result, pos, length - pos); } fis.close(); return result; } public static void createFile(byte[] src, File outFile) throws IOException { FileOutputStream fout = new FileOutputStream(outFile); fout.write(src); fout.close(); } public static void createFile(String src, File outFile) throws IOException { createParentDirs(outFile); createFile(src.getBytes(), outFile); } public static void createParentDirs(File file) { String prefix = file.getAbsolutePath().substring(0, file.getAbsolutePath().lastIndexOf(File.separator)); new File(prefix).mkdirs(); } }