Java FileInputStream Copy copyFile(final File in, final File out)

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

Description

Copy a file

License

Open Source License

Parameter

Parameter Description
in src file
out dest file

Exception

Parameter Description
FileNotFoundException an exception

Declaration

protected static void copyFile(final File in, final File out) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

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

public class Main {
    /** Buffer size.*/
    protected static final int BUFSIZE = 1024;

    /**/*from  w  ww  . j  a  v a2 s.c  o  m*/
     * Copy a file
     * @param in src file
     * @param out dest file
     * @throws FileNotFoundException
     */
    protected static void copyFile(final File in, final File out) throws IOException {
        FileInputStream fis = new FileInputStream(in);
        FileOutputStream fos = new FileOutputStream(out);

        byte[] buf = new byte[BUFSIZE];
        int i = 0;
        try {
            while ((i = fis.read(buf)) != -1) {
                fos.write(buf, 0, i);
            }
            fis.close();
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. copyFile(File targetFile, File file)
  2. copyFile(File targetFile, File file)
  3. copyFile(final File from, final File to)
  4. copyFile(final File fromFile, final File toFile)
  5. copyFile(final File fromFile, final File toFile)
  6. copyFile(final File oldfile, final File newfile)
  7. copyFile(final File source, final File dest)
  8. copyFile(final File source, final File target)
  9. copyFile(final File src, final File dest)