Java FileInputStream Copy copyFile(File src, File dest)

Here you can find the source of copyFile(File src, File dest)

Description

copy File

License

EUPL

Declaration

public static void copyFile(File src, File dest) 

Method Source Code

//package com.java2s;
/*//from   w  ww  .  j  a  va  2  s .  c  om
 * Copyright 2003 Federal Chancellery Austria
 * MOA-ID has been developed in a cooperation between BRZ, the Federal
 * Chancellery Austria - ICT staff unit, and Graz University of Technology.
 *
 * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
 * the European Commission - subsequent versions of the EUPL (the "Licence");
 * You may not use this work except in compliance with the Licence.
 * You may obtain a copy of the Licence at:
 * http://www.osor.eu/eupl/
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the Licence is distributed on an "AS IS" basis,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the Licence for the specific language governing permissions and
 * limitations under the Licence.
 *
 * This product combines work with different licenses. See the "NOTICE" text
 * file for details on the various modules and licenses.
 * The "NOTICE" text file is part of the distribution. Any derivative works
 * that you distribute must include a readable copy of the "NOTICE" text file.
 */

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Main {
    public static void copyFile(File src, File dest) {
        try {
            copy(new FileInputStream(src), new FileOutputStream(dest));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void copy(InputStream fis, OutputStream fos) {
        try {
            byte[] buffer = new byte[0xFFFF];
            for (int len; (len = fis.read(buffer)) != -1;)
                fos.write(buffer, 0, len);
        } catch (IOException e) {
            System.err.println(e);
        } finally {
            if (fis != null)
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            if (fos != null)
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
        }
    }
}

Related

  1. copyFile(File sourceFile, File targetFile)
  2. copyFile(File sourceFile, File targetFile)
  3. copyFile(File sourceFile, String newFileName)
  4. copyFile(File sourceLocation, File targetLocation)
  5. copyFile(File src, File dest)
  6. copyFile(File src, File dest)
  7. copyFile(File src, File dest)
  8. copyFile(File src, File dest)
  9. copyFile(File src, File dest)