Here you can find the source of copyFile(File inputFile, File outputFile)
Parameter | Description |
---|---|
inputFile | a parameter |
outputFile | a parameter |
Parameter | Description |
---|
public static void copyFile(File inputFile, File outputFile) throws IOException
//package com.java2s; /*/*from ww w . j av a 2 s . c o m*/ * Copyright (c) 2007-2012 The Broad Institute, Inc. * SOFTWARE COPYRIGHT NOTICE * This software and its documentation are the copyright of the Broad Institute, Inc. All rights are reserved. * * This software is supplied without any warranty or guaranteed support whatsoever. The Broad Institute is not responsible for its use, misuse, or functionality. * * This software is licensed under the terms of the GNU Lesser General Public License (LGPL), * Version 2.1 which is available at http://www.opensource.org/licenses/lgpl-2.1.php. */ import java.io.*; public class Main { /** * Copy a file from one location to another, using buffered writing * * @param inputFile * @param outputFile * @throws java.io.IOException */ public static void copyFile(File inputFile, File outputFile) throws IOException { OutputStream out = null; InputStream in = null; try { in = new FileInputStream(inputFile); out = new FileOutputStream(outputFile); byte[] buffer = new byte[64000]; int bytes_read; while ((bytes_read = in.read(buffer)) != -1) { out.write(buffer, 0, bytes_read); } } catch (Exception e) { outputFile.delete(); throw new RuntimeException( "<html>Error copying file: " + outputFile.getAbsoluteFile() + "<br/>" + e.toString()); } finally { if (in != null) { in.close(); } if (out != null) { out.flush(); out.close(); } } } }