Here you can find the source of copyFile(File inFile, File outFile)
private static File copyFile(File inFile, File outFile)
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { private static File copyFile(File inFile, File outFile) { try {//from w ww. j ava2s . c om assert inFile.isFile(); assert outFile.getParentFile().isDirectory(); InputStream is = new FileInputStream(inFile); copyStreamIntoFile(outFile, is); return outFile; } catch (IOException e) { e.printStackTrace(); } return null; } public static void copyStreamIntoFile(File outFile, InputStream is) throws IOException { OutputStream os = new FileOutputStream(outFile); byte[] buf = new byte[1024]; int len; while ((len = is.read(buf)) > 0) { os.write(buf, 0, len); } is.close(); os.close(); } }