I am looking for a way to convert my old file to a new file after my program processes the file. The new file should contain the current timestamp after it's been processed. For example, my old file is test.txt. After it's been processed, it should change to test2017-10-13.txt. I have searched for the solution around internet, but I still can't make it work. Here is my current source code
LocalDate now2 = LocalDate.now();
System.out.println("The current day is :" +now2);
File oldFile1 = new File("C:\\Users\\user\\Desktop\\test.txt");
File newFile1 = new File("C:\\Users\\user\\Desktop\\test"+now2+".txt");
boolean success = oldFile1.renameTo(newFile1);
System.out.println(success);
This is my sample output
The current day is :2017-10-13
false
Is it a known bug with java? I found this information online. Is there any method to do it without copying out the contents from the older file and writing it into the new file ?