Java Copy Directory copyDirectory(File srcPath, File dstPath)

Here you can find the source of copyDirectory(File srcPath, File dstPath)

Description

copy Directory

License

Open Source License

Declaration

public static void copyDirectory(File srcPath, File dstPath) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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 {

    public static void copyDirectory(File srcPath, File dstPath) throws IOException {
        if (srcPath.isDirectory()) {
            if (!dstPath.exists()) {
                dstPath.mkdirs();/*from w w w.  j a va  2  s .  c  o  m*/
            }
            String files[] = srcPath.list();
            for (int i = 0; i < files.length; i++) {
                copyDirectory(new File(srcPath, files[i]), new File(dstPath, files[i]));
            }
        } else {
            if (srcPath.exists()) {
                InputStream in = new FileInputStream(srcPath);
                OutputStream out = new FileOutputStream(dstPath);
                byte[] buf = new byte[1024];
                int len;
                while ((len = in.read(buf)) > 0) {
                    out.write(buf, 0, len);
                }
                in.close();
                out.close();
            }
        }
    }
}

Related

  1. copyDirectory(File srcDir, File dstDir)
  2. copyDirectory(File srcDir, File dstDir)
  3. copyDirectory(File srcDir, File dstDir)
  4. copyDirectory(File srcFile, File destFile)
  5. copyDirectory(File srcPath, File dstPath)
  6. copyDirectory(final File sourceDir, final File destDir)
  7. copyDirectory(final File src, final File dest)
  8. copyDirectory(final String sourceDir, final String targetDir)
  9. copyDirectory(String sourceDir, String targetDir)