Here you can find the source of copyFile(File from, File to)
Parameter | Description |
---|---|
from | The original location of the file. |
to | The location the file will be copied to. |
Parameter | Description |
---|---|
IOException | If an error is encountered while copying. |
public static void copyFile(File from, File to) throws IOException
//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); } } } }