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.
- File Permissions in Java
- Delete a file using Java
- Java Class File
- Java.io.File Class in Java
- How to play an Audio file using Java
- How to run java class file which is in different directory?
- Myth about the file name and class name in Java
- Writing a CSV file in Java using OpenCSV
- Reading a CSV file in Java using OpenCV
- Copying file using FileStreams in Java
- Java | Appending String to a File
- Moving a file from one directory to another using Java
- Size of file on the Internet using Java
- Check if a File is hidden in Java
- File getFreeSpace() 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.