Java FileInputStream Copy copyFile(File destfile, File srcfile)

Here you can find the source of copyFile(File destfile, File srcfile)

Description

Copy source file to destination file.

License

Open Source License

Exception

Parameter Description
SecurityException an exception
IOException an exception

Declaration

public static void copyFile(File destfile, File srcfile) throws IOException 

Method Source Code

//package com.java2s;
/*/*w w w  .ja va 2 s . co m*/
 * @(#)Util.java   1.62 04/06/27
 *
 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

import java.io.*;

public class Main {
    /**
     * Copy source file to destination file.
     *
     * @throws SecurityException
     * @throws IOException
     */
    public static void copyFile(File destfile, File srcfile) throws IOException {
        byte[] bytearr = new byte[512];
        int len = 0;
        FileInputStream input = new FileInputStream(srcfile);
        File destDir = destfile.getParentFile();
        destDir.mkdirs();
        FileOutputStream output = new FileOutputStream(destfile);
        try {
            while ((len = input.read(bytearr)) != -1) {
                output.write(bytearr, 0, len);
            }
        } catch (FileNotFoundException exc) {
        } catch (SecurityException exc) {
        } finally {
            input.close();
            output.close();
        }
    }
}

Related

  1. copyFile(File aSource, File aDest)
  2. copyFile(File base, String relfilepath, File targetdir)
  3. copyFile(File copyFrom, File copyTo)
  4. copyFile(File copyFrom, File copyTo)
  5. copyFile(File destFile, File srcFile)
  6. copyFile(File destination, File source)
  7. copyFile(File existingFile, File destFile)
  8. copyFile(File file, File destPath)