Java BufferedInputStream Copy copyFileToFile(File in, File out)

Here you can find the source of copyFileToFile(File in, File out)

Description

Copies one bin file to other

License

Open Source License

Parameter

Parameter Description
in An input file
out An output file

Exception

Parameter Description
IOException an exception

Declaration

public static void copyFileToFile(File in, File out) throws IOException 

Method Source Code


//package com.java2s;
/*//w w w .  j a v  a 2s  . c o  m
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at license/ESCIDOC.LICENSE
* or http://www.escidoc.org/license.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at license/ESCIDOC.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;

import java.io.File;
import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

public class Main {
    /**
     * Copies one bin file to other 
     * @param in An input file
     * @param out An output file
     * @throws IOException
     */
    public static void copyFileToFile(File in, File out) throws IOException {
        int b; // the byte read from the file
        BufferedInputStream is = new BufferedInputStream(new FileInputStream(in));
        BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(out));
        while ((b = is.read()) != -1) {
            os.write(b);
        }
        is.close();
        os.close();
    }
}

Related

  1. copyFile(String src, String dest)
  2. copyFileBytes(String srcFileName, String tarFileName)
  3. copyFileFromStream(InputStream in, File dest)
  4. copyFileFromZipToDir(String zipFile, String fileNamePattern, File dir)
  5. copyFileNormal(File copyFrom, File copyTo)
  6. copyFileToStream(File from, OutputStream out)
  7. copyFileToStream(File input, OutputStream os)
  8. copyFileToTemp(InputStream is, String dirName, String fileName)
  9. copyFileUnique(File in, File outDir)