Here you can find the source of copyFile(File source, File destination)
public static void copyFile(File source, File destination) throws IOException
//package com.java2s; /**// w ww .j ava 2 s. c o m * Copyright 2010, Alvin Alexander, http://devdaily.com. * This software is distributed under the terms of the * GNU General Public License. * * This file is part of an application named JustWrite. * * JustWrite is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * JustWrite 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with JustWrite. If not, see <http://www.gnu.org/licenses/>. * */ import java.io.*; public class Main { public static void copyFile(File source, File destination) throws IOException { //if (!source.isFile() || !dest.isFile()) return false; byte[] buffer = new byte[100000]; BufferedInputStream bufferedInputStream = null; BufferedOutputStream bufferedOutputStream = null; try { bufferedInputStream = new BufferedInputStream(new FileInputStream(source)); bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(destination)); int size; while ((size = bufferedInputStream.read(buffer)) > -1) { bufferedOutputStream.write(buffer, 0, size); } } catch (IOException e) { // TODO may want to do something more here throw e; } finally { try { if (bufferedInputStream != null) { bufferedInputStream.close(); } if (bufferedOutputStream != null) { bufferedOutputStream.flush(); bufferedOutputStream.close(); } } catch (IOException ioe) { // TODO may want to do something more here throw ioe; } } } }