Web Tutorials :: Files :: 49. How do I copy a file to a directory?
Description: This Java tutorial describes how to copy a file to a directory using Commons IO.
The copyFileToDirectory() method of the FileUtils class of the ApacheSW Commons IOS library allows us to copy a file to a directory. It takes the source file as its first parameter and the destination directory as its second argument. If the destination directory doesn't exist, it will be created. The CopyFileToDirectoryTest class demonstrates this.
Before executing CopyFileToDirectoryTest, I had the test1.txt source file located at the root level of my project.
After executing CopyFileToDirectoryTest, you can see that the test-directory directory was created, with a copy of test1.txt in that directory.
Files :: How do I move a file to a directory?