Here you can find the source of copyFileToFile(File in, File out)
Parameter | Description |
---|---|
in | An input file |
out | An output file |
Parameter | Description |
---|---|
IOException | an exception |
public static void copyFileToFile(File in, File out) throws IOException
//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(); } }