Java FileInputStream Copy copyFile(File inputFile, File outputFile)

Here you can find the source of copyFile(File inputFile, File outputFile)

Description

Copy a file from one location to another, using buffered writing

License

LGPL

Parameter

Parameter Description
inputFile a parameter
outputFile a parameter

Exception

Parameter Description

Declaration


public static void copyFile(File inputFile, File outputFile) throws IOException 

Method Source Code

//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();
            }
        }
    }
}

Related

  1. copyFile(File in, File out)
  2. copyFile(File inFile, File outFile)
  3. copyFile(File inFile, File outFile)
  4. copyFile(File input, File output)
  5. copyFile(File inputFile, File outputFile)
  6. copyFile(File inputFile, File outputFile)
  7. copyFile(File inputFile, OutputStream os)
  8. copyFile(File of, File nf)
  9. copyFile(File oldFile, File newFile)