![]() |
The Java Developers Almanac 1.4 |
|
e1072. Copying a Directory // Copies all files under srcDir to dstDir.
// If dstDir does not exist, it will be created.
public void copyDirectory(File srcDir, File dstDir) throws IOException {
if (srcDir.isDirectory()) {
if (!dstDir.exists()) {
dstDir.mkdir();
}
String[] children = srcDir.list();
for (int i=0; i<children.length; i++) {
copyDirectory(new File(srcDir, children[i]),
new File(dstDir, children[i]));
}
} else {
// This method is implemented in e1071 Copying a File
copyFile(srcDir, dstDir);
}
}
e29. Creating a Directory e30. Deleting a Directory e31. Listing the Files or Subdirectories in a Directory e32. Listing the File System Roots e33. Traversing the Files and Directories Under a Directory
© 2002 Addison-Wesley. |