How to rename a file in java

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:

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *