Here you can find the source of copyFile(String src, String dest)
Parameter | Description |
---|---|
src | The path of the source file |
dest | The location to copy the file to. |
Parameter | Description |
---|---|
FileNotFoundException | If the source file could not be found |
IOException | If we encountered some sort of read/write error |
public static void copyFile(String src, String dest) throws FileNotFoundException, IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; public class Main { /**//w w w . ja v a2s.com * Copies a file. * * @param src The path of the source file * @param dest The location to copy the file to. * * @throws FileNotFoundException If the source file could not be found * @throws IOException If we encountered some sort of read/write error */ public static void copyFile(String src, String dest) throws FileNotFoundException, IOException { FileInputStream in = new FileInputStream(new File(src)); FileOutputStream out = new FileOutputStream(new File(dest)); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) out.write(buf, 0, len); in.close(); out.close(); } }