Advertise with us

How can I rename a file in Java?

How can I rename a file from

File temporaryFile = File.createTempFile();


And if newfileName is exists then its fails.

How do I do a force rename?

Last updated:10/23/2013 12:47:48 AM

2 Answers

Samuel Fernandes
Samuel Fernandes

public void forceRename(File source, File target) throws IOException

   if (target.exists()) target.delete();

Donna Klinton
Donna Klinton

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