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

重命名文件或目录

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

512
重命名文件或目录

import java.io.File;
/** 来自 nowjava.com - 时  代  Java**/

public class Main {

  public void m() {

    // File (or directory) with old name

    File file = new File("oldname");


    // File (or directory) with new name

    File file2 = new File("newname");


    // Rename file (or directory)

    boolean success = file.renameTo(file2);

    if (!success) {

      // File was not successfully renamed

    }/**来自 时 代 J a v a 公 众 号**/

  }

}