Here you can find the source of copyFile(File src, File dest)
public static void copyFile(File src, File dest)
//package com.java2s; /****************************************************************************** * Copyright (c) 2010 Oracle/*from w w w.jav a2s . c om*/ * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Original file was copied from * org.eclipse.wst.common.project.facet.core.util.internal.FileUtil * ******************************************************************************/ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.OutputStream; public class Main { public static void copyFile(File src, File dest) { if (src == null || (!src.exists()) || dest == null || dest.isDirectory()) { return; } byte[] buf = new byte[4096]; OutputStream out = null; FileInputStream in = null; try { out = new FileOutputStream(dest); in = new FileInputStream(src); int avail = in.read(buf); while (avail > 0) { out.write(buf, 0, avail); avail = in.read(buf); } } catch (Exception e) { e.printStackTrace(); } finally { try { if (in != null) in.close(); } catch (Exception ex) { // ignore } try { if (out != null) out.close(); } catch (Exception ex) { // ignore } } } }