Here you can find the source of copyFile(File source, File dest)
Parameter | Description |
---|---|
source | File to be copied |
dest | File where to put the copy of source |
Parameter | Description |
---|
public static void copyFile(File source, File dest) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { /**// www.jav a 2 s. c om * * @param source File to be copied * @param dest File where to put the copy of source * @throws java.io.IOException */ public static void copyFile(File source, File dest) throws IOException { if (!dest.exists()) { dest.createNewFile(); } InputStream in = null; OutputStream out = null; try { in = new FileInputStream(source); out = new FileOutputStream(dest); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } } finally { in.close(); out.close(); } } }