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.
- Java.io.File Class in Java
- Java Class File
- Delete a file using Java
- File Permissions in Java
- Moving a file from one directory to another using Java
- How to play an Audio file using Java
- Java | Appending String to a File
- How to run java class file which is in different directory?
- Reading a CSV file in Java using OpenCV
- Myth about the file name and class name in Java
- Writing a CSV file in Java using OpenCSV
- Copying file using FileStreams in Java
- Check if a File is hidden in Java
- Size of file on the Internet using Java
- File setExecutable() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.