File.renameTo(File dest) has the following syntax.
public boolean renameTo(File dest)
In the following code shows how to use File.renameTo(File dest) method.
//from w w w . j av a2 s. c o m import java.io.File; public class Main { public static void main(String[] args) { // create new File objects File f = new File("C:/test.txt"); File f1 = new File("C:/testA.txt"); // rename file boolean bool = f.renameTo(f1); // print System.out.print("File renamed? " + bool); } }
The code above generates the following result.