views:

62

answers:

2

hello, i have an exsting file in my HDD and i want rename this file.

+4  A: 

Like this:

new File(path).renameTo(new File(newPath));
SLaks
you don't need path ??
Mercer
sorry i don't see correctly
Mercer
What on earth do you mean?
SLaks
+1  A: 

You may look at commons-io FileUtils.moveFile. That method tries File.renameTo, and if that fails, tries to copy&delete the file (e.g. when moving from one drive to another).

If you use File.renameTo directly (which should suffice if you only want to rename a file in the same directory), make sure you evaluate the returned boolean value!

Christian Semrau