Here you can find the source of copyFile(File src, File dest)
Parameter | Description |
---|---|
src | The source. |
dest | The destination. |
Parameter | Description |
---|---|
IOException | an exception |
public static void copyFile(File src, File dest) throws IOException
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { /**//www. jav a 2 s.c om * Copies a file. * * @param src The source. * @param dest The destination. * @throws IOException */ public static void copyFile(File src, File dest) throws IOException { if (src.exists() && !src.isDirectory()) { InputStream in = new FileInputStream(src); OutputStream out = new FileOutputStream(dest); // Transfer bytes from in to out byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); } } }