01: //==============================================================================
02: //===
03: //=== CopyFiles
04: //===
05: //==============================================================================
06: //=== Lifted from the net -
07: //=== http://forum.java.sun.com/thread.jspa?threadID=328293&messageID=1334818
08: //==============================================================================
09:
10: package org.fao.geonet.util;
11:
12: import java.io.*;
13: import java.nio.channels.FileChannel;
14:
15: public class FileCopyMgr {
16:
17: private static void copy(File source, File target)
18: throws IOException {
19: FileChannel sourceChannel = new FileInputStream(source)
20: .getChannel();
21: FileChannel targetChannel = new FileOutputStream(target)
22: .getChannel();
23: sourceChannel
24: .transferTo(0, sourceChannel.size(), targetChannel);
25: sourceChannel.close();
26: targetChannel.close();
27: }
28:
29: public static void copyFiles(String strPath, String dstPath)
30: throws IOException {
31:
32: //System.out.println("Copying "+strPath+" to "+dstPath);
33: File src = new File(strPath);
34: File dest = new File(dstPath);
35: if (src.isDirectory()) {
36: if (dest.exists() != true)
37: dest.mkdirs();
38: String list[] = src.list();
39:
40: for (int i = 0; i < list.length; i++) {
41: String dest1 = dest.getAbsolutePath() + File.separator
42: + list[i];
43: String src1 = src.getAbsolutePath() + File.separator
44: + list[i];
45: copyFiles(src1, dest1);
46: }
47: } else {
48: boolean ready = dest.createNewFile();
49: copy(src, dest);
50: }
51: }
52: }
53: //==============================================================================
|