Here you can find the source of copyFile(File src, File dest)
public static boolean copyFile(File src, File dest)
//package com.java2s; /*//from ww w . j a v a 2s . c o m * Copyright (c) 2008 Los Alamos National Security, LLC. * * Los Alamos National Laboratory * Research Library * Digital Library Research & Prototyping Team * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * */ import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { public static boolean copyFile(File src, File dest) { InputStream in = null; OutputStream out = null; byte[] buf = null; int bufLen = 20000 * 1024; try { in = new BufferedInputStream(new FileInputStream(src)); out = new BufferedOutputStream(new FileOutputStream(dest)); buf = new byte[bufLen]; byte[] tmp = null; int len = 0; while ((len = in.read(buf, 0, bufLen)) != -1) { tmp = new byte[len]; System.arraycopy(buf, 0, tmp, 0, len); out.write(tmp); } } catch (IOException e) { e.printStackTrace(); return false; } finally { if (in != null) try { in.close(); } catch (Exception e) { } if (out != null) try { out.close(); } catch (Exception e) { } } return true; } }