printWriter rename Example
printWriter class renameTo example. This example shows you how to use renameTo method.
PrintWriter class renameTo example. method generates boolean results.method changes the name of the abstract pathname file or directory. if successful it returns true otherwise false.method cannot rename any predefined system files, something that relate to system authorizations.
Here is the code:-
/**
* @Program uses renameTo method to over write any file
* or directory name.
* RenameTo.java
* Author:-RoseIndia Team
* Date:-30-june-2008
*/
import java.io.File;
public class RenameTo {
public static void main(String args[]) {
File f1 = new File("/home/mahendra/Baadshah");
File f2 = new File("/home/mahendra/twinkle");
System.out.println("'renameTo'method result");
System.out.println(f1.renameTo(f2));
File user_name = new File("/home/mahendra/");
File tally = new File("/home/krishna/");
System.out.println("'false' is returned as it is the ");
System.out.println("system user name that is been created early at the");
System.out.println("time of installation of the operating system");
System.out.println(user_name.renameTo(tally));
}
} |
Output of the program:-
'renameTo' method result
true
'false' is returned as it is the
system user name that is been created early at the
time of installation of the operating system
false |
|