Java FileInputStream Copy copyFile(File from, File to)

Here you can find the source of copyFile(File from, File to)

Description

Copy a file from one location to another.

License

Open Source License

Parameter

Parameter Description
from The original location of the file.
to The location the file will be copied to.

Exception

Parameter Description
IOException If an error is encountered while copying.

Declaration

public static void copyFile(File from, File to) throws IOException 

Method Source Code


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

import java.io.*;

public class Main {
    /**/*from  w  ww. ja v a2 s  . c o m*/
     * Copy a file from one location to another. The file will not be deleted.
     *
     * @param from The original location of the file.
     * @param to The location the file will be copied to.
     * @throws IOException If an error is encountered while copying.
     */
    public static void copyFile(File from, File to) throws IOException {
        try (InputStream in = new FileInputStream(from); OutputStream out = new FileOutputStream(to)) {
            byte[] buff = new byte[1024];
            int len;
            while ((len = in.read(buff)) > 0) {
                out.write(buff, 0, len);
            }
        }
    }
}

Related

  1. copyFile(File from, File to)
  2. copyFile(File from, File to)
  3. copyFile(File from, File to)
  4. copyFile(File from, File to)
  5. copyFile(File from, File to)
  6. copyFile(File from, File to, byte[] buf)
  7. copyFile(File from, File toDir)
  8. copyFile(File from, File toFile)
  9. copyFile(File fromFile, File toFile)