Here you can find the source of copyFile(String srcFile, String destFile)
public static File copyFile(String srcFile, String destFile) throws SecurityException, IOException
//package com.java2s; /*/*from w w w.j av a 2 s . c o m*/ * $Id$ * * Copyright (C) 2003-2015 JNode.org * * 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 Street, Fifth Floor, Boston, MA 02110-1301 USA. */ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static File copyFile(String srcFile, String destFile) throws SecurityException, IOException { return copyInputStreamToFile(new FileInputStream(new File(srcFile)), destFile); } public static File copyInputStreamToFile(InputStream src, String destFile) throws SecurityException, IOException { File dest = new File(destFile); if (dest.exists()) dest.delete(); FileOutputStream fos = null; try { fos = new FileOutputStream(dest); byte[] buffer = new byte[1024]; int read = -1; do { read = src.read(buffer, 0, buffer.length); if (read > 0) { fos.write(buffer, 0, read); } } while (read != -1); } finally { if (src != null) src.close(); if (fos != null) { fos.flush(); fos.close(); } } return dest; } }