/**
* Copy a directory and its subdirectories, files to another directory
* @param src
* @param dest
* @throws ioexception/
private void CopyFolder (file src, file dest) throws IOException {
if (src.isdirectory ()) {
if (!dest.exists ()) {
Dest.mkdir ();
}
String files[] = Src.list ();
for (String file:files) {
file Srcfile = new file (src, file);
File DestFile = new file (dest, file);
Recursive replication
copyfolder (srcfile, destfile);
}
} else {inputstream in
= new FileInputStream (SRC);
OutputStream out = new FileOutputStream (dest);
byte[] buffer = new byte[1024];
int length;
while (length = in.read (buffer) > 0) {
out.write (buffer, 0, length);
}
In.close ();
Out.close ();
}
Ps:apache Commons-io Package, Fileutils has related methods, Ioutils is generally copy files.
Deletes the directory structure fileutils.deletedirectory (dest);
Recursively copy directory and file Fileutils.copydirectory (SRC, dest);