HOW CAN I RENAME A FILE IN JAVA?

Simons Hood

Total Post:70

Points:494
Posted by  Simons Hood
Java 
 1971  View(s)
Ratings:
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?
  1. Samuel Fernandes

    Post:159

    Points:1117
    Re: How can I rename a file in Java?

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

  1. Donna Klinton

    Post:3

    Points:21
    Re: How can I rename a file in Java?

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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!