How to rename a file in java

Last updated on March 19th, 2017 at 10:03 am

Previous
Next
In this post, we will see how to rename a file in java. We can use java.io.File ‘s rename(File dest) method to rename a file. rename method returns true if operation is success else returns false. It can use this method to move a file also.

You should always check if rename operation is successful or not because it does not throw any exception

Java Program:

When I ran above program, I got following output:

Previous
Next

Join Our News Letter - Stay Updated

Subscribe to Awesome Java Content.

Add Comment

Join Our News Letter - Stay Updated

Subscribe to Awesome Java Content.
You can like our facebook page Java2blog