Here you can find the source of copyFile(File from, File to)
public static void copyFile(File from, File to)
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { public static void copyFile(File from, File to) { try {// w w w . ja v a 2 s .c o m FileInputStream inputStream = new FileInputStream(from); FileOutputStream outputStream = new FileOutputStream(to); byte[] b = new byte[1024]; int n = 0; while ((n = inputStream.read(b)) != -1) { outputStream.write(b, 0, n); } inputStream.close(); outputStream.flush(); outputStream.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public static void copyFile(String from, String to) { try { FileInputStream inputStream = new FileInputStream(from); FileOutputStream outputStream = new FileOutputStream(to); byte[] b = new byte[1024]; int n = 0; while ((n = inputStream.read(b)) != -1) { outputStream.write(b, 0, n); } inputStream.close(); outputStream.flush(); outputStream.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }