File RenameTo() Example
Renames the file denoted by this abstract pathname.
File class RenameTo() method example. This example shows you how to use RenameTo method.This method Renames the file denoted by this abstract pathname.
Here is the code:-
/**
* @Program that Renames the file denoted by this abstract pathname.
* RenameTo.java
* Author:-RoseIndia Team
* Date:-30-May-2008
*/
import java.io.*;
public class RenameTo {
public static void main(String[] args) {
File f = new File("/home/girish/Desktop/g.txt");
File f1 = new File("/home/girish/Desktop/girish.txt");
if(f.exists())
{
System.out.println("File renamed Successfully: "+f.renameTo(f1));
}
else
{
System.out.println("File cannot be renamed Successfully: ");
}
}
} |
Output of the Program
| File renamed Successfully: true |
|