Renaming files using File object - Java File Path IO

Java examples for File Path IO:File Rename

Description

Renaming files using File object

Demo Code

import java.io.File;
import java.io.IOException;

public class Main {
  public static void main(String[] arg) throws IOException {
    File f = new File("c:/myfile.txt");
    if (f.renameTo(new File("c:/savedmyfile.txt")))
          System.out.println("File renamed.");
    else/*w ww . ja  v  a 2 s.c om*/
          System.out.println("File not renamed.");
  }
}

Related Tutorials