How to rename file in Java?

The following example explain how to rename file in Java with dest), this method is really platform-dependent.

package com.nourit.javaIO;


public class RenameFile {

  public static void main(String[] args) {
    File newfile =new File("D:/tmp/nourit.txt");
    File oldfile =new File("D:/tmp/nourit-new.txt");

      System.out.println("Rename succesful: " + newfile.getName());
      System.out.println("Rename failed");


Rename succesful: nourit-new.txt



IT Training Center for Java and Web technology. If you enjoy and like our tutorials and believe in our mission, Please Subscribe us on Youtube and follow us on Twitter, or befriend us on Facebook or Google Plus.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.