Java FileInputStream Copy copyFile(final String sourceFile, final String destinationFile)

Here you can find the source of copyFile(final String sourceFile, final String destinationFile)

Description

This does a binary file copy

License

Open Source License

Declaration

public static void copyFile(final String sourceFile, final String destinationFile) throws IOException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2012 eBay Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://  www .  ja v  a  2s .  c  o  m
 *     eBay Inc. - initial API and implementation
 *******************************************************************************/

import java.io.FileInputStream;

import java.io.FileOutputStream;
import java.io.IOException;

public class Main {
    /** This does a binary file copy
     */
    public static void copyFile(final String sourceFile, final String destinationFile) throws IOException {
        final FileInputStream fis = new FileInputStream(sourceFile);
        final FileOutputStream fos = new FileOutputStream(destinationFile);
        try {
            final byte[] buffer = new byte[4096];
            int numBytesRead;
            do {
                numBytesRead = fis.read(buffer);
                if (numBytesRead > 0) {
                    fos.write(buffer, 0, numBytesRead);
                }
            } while (numBytesRead >= 0);
        } finally {
            try {
                fos.flush();
            } finally {
                try {
                    fos.close();
                } finally {
                    fis.close();
                }
            }
        }
    }
}

Related

  1. copyFile(final File src, final File dst)
  2. copyFile(final File srcFile, final File destFile)
  3. copyFile(final File srcPath, final File dstPath)
  4. copyFile(final InputStream in, final File destFile)
  5. copyFile(final String from, final String to)
  6. copyFile(final String sourceFilePath, final String destFilePath)
  7. copyFile(final String sSource, final String sDest)
  8. copyFile(InputStream in, File dst)
  9. copyFile(InputStream in, File to)