Java | Renaming a file Last Updated : 26 Mar, 2018 Comments Improve Suggest changes Like Article Like Report In Java we can rename a file using renameTo(newName) method that belongs to the File class. Declaration: Following is the declaration for java.io.File.renameTo(File dest) method: public boolean renameTo(File dest) Parameters: dest - The new abstract pathname for the existing abstract pathname. Exception: 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 // Java program to rename a file. import java.io.File; public class GeeksforGeeks { public static void main(String[] args) { File oldName = new File("C:\Users\Siddharth\Desktop\java.txt"); File newName = new File("C:\Users\Siddharth\Desktop\GeeksforGeeks.txt"); if (oldName.renameTo(newName)) System.out.println("Renamed successfully"); else System.out.println("Error"); } } Renamed successfully Comment More infoAdvertise with us Next Article Java | Renaming a file G geeksforgeeks user Follow Improve Article Tags : Java Practice Tags : Java Similar Reads Delete a File Using Java Java provides methods to delete files programmatically. In contrast to normal delete operations in any operating system, files being deleted using the Java program are deleted permanently without being moved to the trash/recycle bin. Example: A basic program to delete the file from a static path.Jav 2 min read File Permissions in Java Java provides a number of method calls to check and change the permission of a file, such as a read-only file can be changed to have permissions to write. File permissions are required to be changed when the user wants to restrict the operations permissible on a file. For example, file permission ca 3 min read Java File Class Java File class is a representation of a file or directory pathname. Because file and directory names have different formats on different platforms, a simple string is not adequate to name them. Java File class contains several methods for working with the pathname, deleting and renaming files, crea 6 min read Java Class File A Java class file is a file containing Java bytecode and having .class extension that can be executed by JVM. A Java class file is created by a Java compiler from .java files as a result of successful compilation. As we know, a single Java programming language source file (or we can say .java file) 5 min read How to rename all files of a folder using Java? When transferring files from the camera folder to a workspace where we would like to analyze the pictures, it becomes difficult to deal with long files and type them out again and again when testing them through code. Also, the number of files might be too large to manually rename each one of them. 4 min read File renameTo() method in Java with examples The renameTo() method is a part of File class. The renameTo() function is used to rename the abstract path name of a File to a given path name. The function returns true if the file is renamed else returns false Function Signature: public boolean renameTo(File destination) Syntax: file.renameTo(File 2 min read How to Read a File using Applet? In this article, we will learn how to read the content of the file using Java and display those contents using Applet. Approach UsedThe user should type the name of the file in the input field that asks for the filename in the output applet window. If the file is already present, it will display the 2 min read Create a Temporary File in Java In Java, we can create a temporary file using an existing method known as File.createTempFile() method which creates a new empty file on the specified directory. The createTempFile() function creates a temporary file in a given directory (if the directory is not mentioned then a default directory is 4 min read FileStore name() method in Java with Examples The name() method of a FileStore class is used to return the name of this file store as a String. The format of the name is typically the name of the storage pool or volume. The string returned by this method may differ from the string returned by the toString() method. Syntax: public abstract Strin 2 min read Java FileWriter Class Java FileWriter class of the java.io package is used to write data in character form to a file. The FileWriter class in Java is used to write character-oriented data to a file. It is a character-oriented class that is used for file handling in Java.This Class inherits from OutputStreamWriter class w 5 min read Like