How to Copy Non Empty Directory with Files in Java- Example Tutorial

yotube
0
It's easy to copy a file or an empty directory in Java as you can use Files.copy(fromPath, toPath) from Java 7, but, unfortunately, it's not as easy to copy a non-empty directory with all its files and subdirectories in Java, much like deleting a non-empty directory. There is no method in Java IO API which copies everything inside one directory to another. The copy(source, target, CopyOption...) method can copy directories, but files inside the directories are not copied. So the new directory will be empty even if the original directory contains files and folders. Similarly, the copy fails if the target directory already exists, unless the REPLACE_EXISTING copy option is specified.

Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !
To Top