File rename

In this chapter you will learn:

  1. How to rename a file

Rename a file

boolean renameTo(File dest) renames the file denoted by this abstract pathname.

The return value from the method above tells if the renaming action is successful. It may return false if the file is opened in another application.

import java.io.File;
//j  ava  2s.  c o m
public class Main {

  public static void main(String[] args) {
    File file = new File("c:/a.htm");
    file.renameTo(new File("c:/abc.html"));
    
  }
}

Next chapter...

What you will learn in the next chapter:

  1. How to get the file last modified time
  2. How to change last-modified time