Java FileInputStream Copy copyFile(File in, File out)

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

Description

copy File

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;
/*/* w  w  w  . j  a va2s. co  m*/
 * Stage - Spatial Toolbox And Geoscript Environment 
 * (C) HydroloGIS - www.hydrologis.com 
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * (http://www.eclipse.org/legal/epl-v10.html).
 */

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

import java.io.IOException;

public class Main {
    public static void copyFile(String fromFile, String toFile) throws IOException {
        File in = new File(fromFile);
        File out = new File(toFile);
        copyFile(in, out);
    }

    public static void copyFile(File in, File out) throws IOException {
        FileInputStream fis = new FileInputStream(in);
        FileOutputStream fos = new FileOutputStream(out);
        byte[] buf = new byte[1024];
        int i = 0;
        while ((i = fis.read(buf)) != -1) {
            fos.write(buf, 0, i);
        }
        fis.close();
        fos.close();
    }
}

Related

  1. copyFile(File fromFile, File toFile)
  2. copyFile(File fromFile, File toFile, IProgressMonitor monitor)
  3. copyFile(File in, File out)
  4. copyFile(File in, File out)
  5. copyFile(File in, File out)
  6. copyFile(File in, File out)
  7. copyFile(File in, File out)
  8. copyFile(File in, File out)
  9. copyFile(File in, File out)