How to rename a file in java

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 0 Flares ×

You can easily rename a file in Java using the renameTo()  method. But there is a catch. This methods works in a platform specific manner. The file may get renamed if tried on a linux machine and may fail on windows. Hence it is very important to look at the return value. Method renameTo() returns a boolean value and you should check this for true to make sure that the rename operation has indeed succeeded.