Hi I am trying to rename the excel file using but, it was not successful . Please help me out
String path = "C:\Users\nvr\Desktop\sample.xls";
File file = new File(path);
File file2 = new File(file.getParentFile().getPath() + "/" + "temp_" + file.getName());
boolean success = file.renameTo(file2);
if (!success) {
System.out.println("File was not successfully renamed");
} else {
System.out.println("File was successfully renamed");
}
I got the output as : File was not successfully renamed
Can you let me know, If i am messing up anything in here or is there any other way to rename the xls files.
Thanks,
NVR