In Java we can rename a file using renameTo(newName) method that belongs to the File class.
Following is the declaration for java.io.File.renameTo(File dest) method:
public boolean renameTo(File dest)
dest – The new abstract pathname for the existing abstract pathname.
SecurityException : If a security manager exists and its method denies write access to either the old or new pathnames.
NullPointerException : If parameter destination is null.
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.