Here you can find the source of copy(File from, File to)
public static void copy(File from, File to)
//package com.java2s; //License from project: Open Source License import java.io.*; import javax.swing.JOptionPane; public class Main { public static void copy(File from, File to) { try {//from w w w . j ava2 s . co m File w = new File(to, from.getName()); if (!w.exists()) w.createNewFile(); BufferedOutputStream write = new BufferedOutputStream(new FileOutputStream(w)); BufferedInputStream read = new BufferedInputStream(new FileInputStream(from)); byte[] buffer = new byte[1024]; int l = 0; while ((l = read.read(buffer)) > -1) { write.write(buffer, 0, l); } write.flush(); write.close(); read.close(); System.out.println("Copied " + from.getName() + " to " + to.getCanonicalPath()); } catch (IOException e) { JOptionPane.showMessageDialog(null, "Could not copy file " + from.getName() + ": " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } }