From f432dc1e2cec90c7a6bcb669e49044cbc59aac50 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Fri, 13 Aug 2010 10:34:13 +0200 Subject: [PATCH] Useful if org.apache.commons.io.FileUtils not available. --- src/fr/devinsy/util/FileCopier.java | 59 +++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/fr/devinsy/util/FileCopier.java diff --git a/src/fr/devinsy/util/FileCopier.java b/src/fr/devinsy/util/FileCopier.java new file mode 100644 index 0000000..e684415 --- /dev/null +++ b/src/fr/devinsy/util/FileCopier.java @@ -0,0 +1,59 @@ +package fr.devinsy.util; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; + + +/** + * Never used. Prefer org.apache.commons.io.FileUtils class. + */ +public class FileCopier +{ + static final public int BUFFER_SIZE = 4*1024; + + /** + * + */ + static void copy (File source, File target) throws Exception + { + if ((source == null) || (target == null)) + { + throw new Exception("Null parameter."); + } + else + { + FileInputStream in = new FileInputStream(source); + FileOutputStream out = new FileOutputStream(target); + try + { + byte[] buffer = new byte[BUFFER_SIZE]; + boolean ended = false; + while (!ended) + { + int size = in.read(buffer); + if (size == -1) + { + ended = false; + } + else + { + out.write(buffer, 0, size); + } + } + } + finally + { + if (in != null) + { + in.close(); + } + + if (out != null) + { + out.close(); + } + } + } + } +}