Here you can find the source of copyFile(File from, File to)
public static void copyFile(File from, File to) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2007, 2008 Borland Software Corporation and others. * //from w w w. ja v a 2s . 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 * * Contributors: * Borland Software Corporation - initial API and implementation *******************************************************************************/ 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 void copyFile(File from, File to) throws IOException { FileInputStream input = null; FileOutputStream output = null; try { input = new FileInputStream(from); output = new FileOutputStream(to); copyStream(input, output); } finally { if (input != null) { try { input.close(); } catch (IOException e) { } } if (output != null) { try { output.close(); } catch (IOException e) { } } } } public static void copyStream(InputStream input, OutputStream output) throws IOException { byte[] buffer = new byte[8192]; int read; while ((read = input.read(buffer)) > 0) { output.write(buffer, 0, read); } } }