Java File rename

Description

Java File rename

import java.io.File;

public class Main {
  public static void main(String[] args) {
    File oldFile = new File("Main.txt");
    File newFile = new File("Main1.txt");

    boolean fileRenamed = oldFile.renameTo(newFile);
    if (fileRenamed) {
      System.out.println(oldFile + " renamed to " + newFile);
    } else {/* w ww .  j  a  v a  2 s  .c o  m*/
      System.out.println("Renaming " + oldFile + " to " + newFile + " failed.");
    }
  }

}



PreviousNext

Related