Home > DeveloperSection > Forums > How can I rename a file in Java?
Simons Hood
Simons Hood

Total Post:70

Points:494
Posted on    October-22-2013 3:45 AM

 Java Java 
Ratings:


 2 Reply(s)
 1539  View(s)
Rate this:

How can I rename a file from Java.io?

File temporaryFile = File.createTempFile();
temporaryFile.renameTo(newfileName);
And if newfileName is exists then its fails.
How do I do a force rename?


Samuel Fernandes
Samuel Fernandes

Total Post:154

Points:1082
Posted on    October-22-2013 3:58 AM

public void forceRename(File source, File target) throws IOException
{
   if (target.exists()) target.delete();
   source.renameTo(target)
}

Donna Klinton
Donna Klinton

Total Post:3

Points:21
Posted on    October-23-2013 12:47 AM

Hi there
Thanks for your anwser.It's helpful.But i want to know is there any program for that?Thanks

Don't want to miss updates? Please click the below button!

Follow MindStick