I am going to show example which shows how to rename file or directory in Java.
import java.io.File;public class Main{ public static void main(String[] args){ // File (or directory) with old name File oldFile = new File("C:/sampleDir"); // File (or directory) with new name File newFile = new File("C:/sample"); // Rename file (or directory) boolean success = oldFile.renameTo(newFile); if (!success){ System.err.println("Error"); } }}You can copy this example to your IDE and use it for your objectives.
No related posts.

Recent Comments