集册 Java实例教程 重命名文件或空目录

重命名文件或空目录

欢马劈雪     最近更新时间:2020-01-02 10:19:05

420
重命名文件或空目录


import java.io.*;

 

public class Main {/**来 自 NowJava.com**/

 

  public static void main(String[] args) {

    File oldName = new File("C://Folder//source.txt");

    File newName = new File("C://Folder//destination.txt");

     boolean isFileRenamed = oldName.renameTo(newName);

   

     if(isFileRenamed)

       System.out.println("File has been renamed");

     else

       System.out.println("Error renaming the file");

  }
  /**来自 
   时 代      J a v a   公   众 号 - nowjava.com**/

}