Here you can find the source of copyFile(File from, File to, byte[] buf)
public static boolean copyFile(File from, File to, byte[] buf)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class Main { private static final int BUFFER_SIZE = 4096 * 4; public static boolean copyFile(File from, File to, byte[] buf) { if (buf == null) buf = new byte[BUFFER_SIZE]; FileInputStream from_s = null; FileOutputStream to_s = null; try {/*from w w w . j a va2 s. c o m*/ from_s = new FileInputStream(from); to_s = new FileOutputStream(to); for (int bytesRead = from_s.read(buf); bytesRead > 0; bytesRead = from_s .read(buf)) { to_s.write(buf, 0, bytesRead); } to_s.getFD().sync(); } catch (IOException ioe) { return false; } finally { if (from_s != null) { try { from_s.close(); from_s = null; } catch (IOException ioe) { } } if (to_s != null) { try { to_s.close(); to_s = null; } catch (IOException ioe) { } } } return true; } }