Here you can find the source of copyFileBin(File sourceFile, File targetFile)
public static boolean copyFileBin(File sourceFile, File targetFile)
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; public class Main { public static boolean copyFileBin(File sourceFile, File targetFile) { // check deltas boolean deltas = (targetFile.lastModified() != sourceFile .lastModified());/*from w ww . ja v a 2s .com*/ if (!deltas) { deltas = deltas || (targetFile.length() != sourceFile.length()); } if (deltas) { if (!targetFile.exists()) { // create parent directory if necessary File parentDir = targetFile.getParentFile(); if (!parentDir.isDirectory()) { if (!parentDir.mkdirs()) { return false; } } } else { targetFile.delete(); } try { targetFile.createNewFile(); } catch (IOException e) { return false; } FileOutputStream fileO; try { fileO = new FileOutputStream(targetFile.getAbsolutePath(), true); } catch (FileNotFoundException e) { return false; } FileInputStream fileI; try { fileI = new FileInputStream(sourceFile); } catch (FileNotFoundException e) { return false; } try { byte[] buf = new byte[1024]; int len; while ((len = fileI.read(buf)) > 0) { fileO.write(buf, 0, len); } fileI.close(); fileO.flush(); fileO.close(); } catch (IOException e) { try { fileI.close(); } catch (IOException e1) { // ignore } try { fileO.close(); } catch (IOException e1) { // ignore } return false; } targetFile.setLastModified(sourceFile.lastModified()); } return true; } }