You should always check if rename operation is successful or not because it does not throw any exception
Java Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
package org.arpit.java2blog; import java.io.File; public class RenameFileMain { /* * @Author : Aprit Mandliya */ public static void main(String[] args) { System.out.println("-----------------"); // Read the file File configFile=new File("/Users/Arpit/Desktop/config.properties"); // destination file object File configFileNew=new File("/Users/Arpit/Desktop/config_new.properties"); boolean remameSuccess=configFile.renameTo(configFileNew); if(remameSuccess) { System.out.println("Rename operation is successful"); } else { System.out.println("Rename operation is unsuccessful"); } System.out.println("-----------------"); } } |
1 2 3 4 5 |
----------------- Rename operation is successful ----------------- |