Copied from (originally) http://exampledepot.8waytrips.com/egs/java.io/RenameFile.html (archived at the Wayback Machine).

// File (or directory) with old name
File file = new File("oldname");
    
// File (or directory) with new name
File file2 = new File("newname");

if (file2.exists())
   throw new java.io.IOException("file exists");
    
// Rename file (or directory)
boolean success = file.renameTo(file2);

if (!success) {
   // File was not successfully renamed
}

To append to the new file:

java.io.FileWriter out= new java.io.FileWriter(file2, true /*append=yes*/);
Answer from Pierre on Stack Overflow
🌐
Baeldung
baeldung.com › home › java › java io › java – rename or move a file
Rename or Move a File in Java | Baeldung
January 5, 2024 - How to rename or move a file in Java, using JDK6, JDK7, Guava or Apache Commons.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-program-to-rename-a-file
Java Program to Rename a File - GeeksforGeeks
July 23, 2025 - Create another object of the File class and replace the file path with the renaming path of the directory. Use renameTo() method. If rename operation successful then the function returns true.
🌐
TutorialsPedia
tutorialspedia.com › home › java rename all files in folder
java rename all files in folder | TutorialsPedia
While developing a Java application, you may come across a scenario where you have a large number of files in a folder which don’t have required naming standards or conventions that you are in need of. In such a situation, you will wish to have a piece of code that can rename all the files…
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › io › File.html
File (Java Platform SE 8 )
April 21, 2026 - Many aspects of the behavior of this method are inherently platform-dependent: The rename operation might not be able to move a file from one filesystem to another, it might not be atomic, and it might not succeed if a file with the destination abstract pathname already exists.
Find elsewhere
🌐
Unibz
inf.unibz.it › ~calvanese › teaching › 04-05-ip › lecture-notes › uni08 › node11.html
Renaming and deleting a file in Java
File f1 = new File("oldname.txt"); File f2 = new File("newname.txt"); boolean b = f1.renameTo(f2); // if b is true, then the file has been renamed successfully
🌐
Kindle Modding
kindlemodding.org › jailbreaking › post-jailbreak › setting-up-a-hotfix
KindleModding - Setting Up A Hotfix
If you have blocked the updates using renametobin (set to Rename), make sure to revert it beforehand (by selecting Restore), or you will not be able to install the hotfix through the Settings menu · This is not necessary for some types of legacy jailbreaks, check the corresponding page ... If you see any other files on your Kindle ending in .bin, or have a similar name to update.bin.tmp.partial, you must delete them for the hotfix to work.
🌐
TutorialsPoint
tutorialspoint.com › article › rename-multiple-files-using-java
Rename multiple files using Java
July 4, 2020 - import java.io.File; import java.io.IOException; public class Demo{ public static void main(String[] argv) throws IOException{ String path_to_folder = "path\to\folder\where\multiple\files\are\present"; File my_folder = new File(path_to_folder); File[] array_file = my_folder.listFiles(); for (int i = 0; i < array_file.length; i++){ if (array_file[i].isFile()){ File my_file = new File(path_to_folder + "" + array_file[i].getName()); String long_file_name = array_file[i].getName(); String[] my_token = long_file_name.split("\s"); String new_file = my_token[1]; System.out.println(long_file_name); System.out.print(new_file); my_file.renameTo(new File(path_to_folder + "" + new_file + ".pdf")); } } } }
🌐
Mkyong
mkyong.com › home › java › how to rename or move a file in java
How to rename or move a file in Java - Mkyong.com
July 30, 2020 - In Java, we can use the NIO `Files.move(source, target)` to rename or move a file.
🌐
Kubernetes
kubernetes.io › docs › concepts › configuration › configmap
ConfigMaps | Kubernetes
November 21, 2025 - A ConfigMap is an API object used to store non-confidential data in key-value pairs. Pods can consume ConfigMaps as environment variables, command-line arguments, or as configuration files in a volume. A ConfigMap allows you to decouple environment-specific configuration from your container images, so that your applications are easily portable.
🌐
Claude Platform Docs
platform.claude.com › docs › en › agents-and-tools › tool-use › memory-tool
Memory tool - Claude Platform Docs
If the path is a directory, return a "file does not exist" error. ... Deletes the directory and all its contents recursively. The tool description tells Claude it cannot delete the /memories directory itself, so reject a delete whose path is the memory root. ... Destination already exists: Return an error (do not overwrite): "Error: The destination {new_path} already exists" Renames the directory.
🌐
Xiaocaicai
baeldung.xiaocaicai.com › java-how-to-rename-or-move-a-file
Rename or Move a File – Java –重命名或移动一个文件
June 25, 2014 - 在这个快速教程中,我们将学习在Java中重命名/移动一个文件。 · We’ll first look into using the Files and Path classes from NIO, then the Java File class, Google Guava, and finally the Apache Commons IO library.
🌐
Coderanch
coderanch.com › t › 278254 › java › File-rename-Java-API
File rename using Java API (I/O and Streams forum at Coderanch)
October 31, 2006 - You could use Runtime.exec to issue a shell command that does this, but there is no support for this in the Java class libraries. ... Presumably you know about File.renameTo(), right? It's just one file at a time, but you can always write a loop. The bigger headache is remembering to check the return value, and if it's false, figuring out why.
🌐
OpenRocket
openrocket.info › downloads.html
Downloads
OpenRocket is available as packages for Linux, macOS and Windows. A .jar file is also available, as is all of the source code. For most users, we strongly recommend using the package appropriate for your operating system. These packages contain all of the needed dependencies, including the correct version of Java.
🌐
Java Code Geeks
examples.javacodegeeks.com › home › java development › core java › io › file
Rename file/directory - Java Code Geeks
October 26, 2013 - Many aspects of the behavior of this method are inherently platform-dependent: The rename operation might not be able to move a file from one filesystem to another, it might not be atomic, and it might not succeed if a file with the destination abstract pathname already exists. The return value should always be checked to make sure that the rename operation was successful, ... package com.javacodegeeks.snippets.core; import java.io.File; public class RenameFileDirectory { public static void main(String[] args) { File file = new File("C://file.txt"); File newFile = new File("C://new_file.txt"); // Renames the file denoted by this abstract pathname.
🌐
YouTube
youtube.com › watch
How to rename a file in java? - YouTube
#learnwithkrishnasandeep #javacodinginterviewquestions #javaexamples #javaprograms #javatutorials #javaprogramming how to rename a file in java,how to rena...
Published   December 12, 2015
🌐
Coderanch
coderanch.com › t › 380528 › java › rename-file-JAVA
How to rename a file in JAVA ? (Java in General forum at Coderanch)
July 31, 2006 - FileInputStream input = new FileInputStream("file"); BufferedReader fileReader = new BufferedReader(new InputStreamReader(input)); ///// PROCESSING ///////// File destFile = new File("newfilePath"); boolean flag = file.renameTo(destFile); DO you mean to say that i need to close the fileReader ??
🌐
W3Schools
w3schools.com › java › java_oop.asp
Java OOP (Object-Oriented Programming)
close() delimiter() findInLine() findWithinHorizon() hasNext() hasNextBoolean() hasNextByte() hasNextDouble() hasNextFloat() hasNextInt() hasNextLine() hasNextLong() hasNextShort() locale() next() nextBoolean() nextByte() nextDouble() nextFloat() nextInt() nextLine() nextLong() nextShort() radix() reset() useDelimiter() useLocale() useRadix() Java File Methods Java FileInputStream Java FileOutputStream Java BufferedReader Java BufferedWriter Java Iterator Methods Java Collections Methods Java System Methods Java Errors & Exceptions
🌐
ExifTool
exiftool.org
ExifTool by Phil Harvey
GPicSync: Windows/Linux utility to geocode photos from a GPX track log and create KML files · FlickFleck: Tool to transfer images from memory card, rotate, rename, and organize by date · Geotag: Open source Java-based geotagging application · PhotoGrok: Java-based GUI front-end for ExifTool to display images organized by any EXIF tag ·