Renaming a File or Directory - Java File Path IO

Java examples for File Path IO:File Rename

Description

Renaming a File or Directory

Demo Code

import java.io.File;

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
    }//w w w. j  a v  a2 s .  c  om
  }
}

Related Tutorials