From ed595b155f4382a1401d6b47ab316e7e5b223243 Mon Sep 17 00:00:00 2001 From: Robert Greig Date: Wed, 4 Apr 2007 15:19:38 +0000 Subject: Added simeple file copy function. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/M2@525533 13f79535-47bb-0310-9956-ffa450edef68 --- .../main/java/org/apache/qpid/util/FileUtils.java | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'java') diff --git a/java/common/src/main/java/org/apache/qpid/util/FileUtils.java b/java/common/src/main/java/org/apache/qpid/util/FileUtils.java index ba79a6e8d4..3c8d3f916b 100644 --- a/java/common/src/main/java/org/apache/qpid/util/FileUtils.java +++ b/java/common/src/main/java/org/apache/qpid/util/FileUtils.java @@ -158,4 +158,40 @@ public class FileUtils return is; } + + /** + * Copies the specified source file to the specified destintaion file. If the destinationst file does not exist, + * it is created. + * + * @param src The source file name. + * @param dst The destination file name. + */ + public static void copy(File src, File dst) + { + try + { + InputStream in = new FileInputStream(src); + if (!dst.exists()) + { + dst.createNewFile(); + } + + OutputStream out = new FileOutputStream(dst); + + // 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(); + } + catch (IOException e) + { + throw new RuntimeException(e); + } + } } -- cgit v1.2.1