Renaming A File
This programs explains the use of rename function of the class File.A already exisiting file is renamed.
/*
http://www.ProbCOMP.com
This programs explains the use of rename function of the class
File.A already exisiting file is renamed.
*/
import java.io.File;
public class RenameFileDir {
public static void main(String args[]) {
// enter first the names of files as command line argument , first write the oldfile name and then the new file name e.g.
// java RenameFileDir oldfile.txt newfile.txt
File file1 = new File(args[0]);
File file2 = new File(args[1]);
boolean rename = file1.renameTo(file2);
if (rename)
{
System.out.println("File renamed.\n");
}
else
{
System.out.println("File not renamed.\n");
}
}
}
Download Program


