3 ways to Copy a File From One Directory to Another in Java

Even though Java is considered one of the best feature-rich programming language, until Java 7, It didn't have any method to copy a file from one directory to another directory. It did have the java.io.File class, which provides a method to check if a file exists or not and methods for several other file operations but it lacks support for copying file from one folder to another. It was easy to write your own routine to copy a file using FileInputStream or FileChannel, most developers prefer to use Apache Commons IO library; which is not a bad idea at all. Even Joshua Bloch (author of several Java classes in JDK, including Java Collection Framework) advise using libraries instead of reinventing wheels in must read Effective Java book. The Apache Commons IO library provides a class called FileUtils, which contains several file utility methods including one for copying file from one directory to another.
Read more »