I am looking a way for convert my old file to a new file after my program processed the file. The new file will contain current timestamp after it’s been processed.For example, my old file will
test.txt, after it’s been processed, it’s will change to
test2017-10-13.txt. I had searched the solution around internet but I’m still cant 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
Do it a bug reported in java because I found this information online or do there have any method to do it without copy out the contents from older file and write it into new file ?