Hello!!! Why is it that the following code prints the original filename considering that the original file was renamed to "testRename.txt"? Need your help.
import java.io.*;
class TestFileClass {
public static void main(
String[] args) throws IOException {
new File("test.txt"); // does not create a new file
// create a file in the current directory
File f = new File("test1.txt");
System.out.println( f.createNewFile() );
// rename a file
File f2 = new File("testRename.txt");
System.out.println(f.renameTo(f2)); // renames the file on the system
System.out.println( f.getAbsolutePath() ); // returns original filename
System.out.println( "Does old file exist?: " + f.exists() );
System.out.println( "Does new file exist?: " + f2.exists() );
}
}
OUTPUT:
true
true
c:\test1.txt
Does old file exist?: false
Does new file exist?: true
Thank you,
TINA