Problems changing file name
Hi guys,
Im starting to learn java and I'm having a little trouble remaming a file. My program creates the file on the desktop and renames it but when I try to print the name of the file in the console its come up with the original file name.
Any help would be great!! thanks!
import java.util.Scanner;
import java.io.*;
import java.util.*;
class testing{
public static void main(String args[]){
Scanner in = new Scanner(System.in);
File newFile= new File("C:\\Users\\Public\\Desktop\\bren.txt"); //creates a new instance of file
try{
newFile.createNewFile(); //actually creates the file
newFile.renameTo(new File("C:\\Users\\Public\\Desktop\\john.txt")); //renames file
}
catch(Exception e){
}
System.out.println(newFile.getName());
}
}