// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.*;

public class CopyDir {

   public static void main(String[] argv) throws Exception {
      process("C:\\ZZZ", "C:\\ZZZCOPY");
   }

   private static void process(String d1, String d2) throws IOException {
      File f = new File(d1);
      if (f.isDirectory()) {
         (new File(d2)).mkdir();
         String list[] = f.list();
         for (int i = 0; i < list.length; i++) {
            process( d1 + File.separator + list[i],
                    d2 + File.separator + list[i]);
         }
      } else if (f.isFile()) {
         copy(d1, d2);
      }
   }
   public static void copy(String fromname, String toname) throws IOException {
      InputStream is = new FileInputStream(fromname);
      OutputStream os = new FileOutputStream(toname);
      byte[] b = new byte[100000];
      int n;
      while ((n = is.read(b)) >= 0) {
         os.write(b, 0, n);
      }
      is.close();
      os.close();
   }
}
