Why is the date of the file in the following code not changed?
fLocal.location
= Existing file in C:\
fLocal.date
= Date to set in Long
boolean x = new File(fLocal.location).setLastModified(Long.parseLong(fLocal.date));
System.out.println("Changed: " + x);
System.out.println(new Date(new File(fLocal.location).lastModified()));
System.out.println(new Date(Long.parseLong(fLocal.date)));
Output:
Changed: false
Fri Feb 15 23:02:51 CET 2013
Fri Feb 15 22:49:34 CET 2013
exists()
on your File Object before you try to change it to ensure you actually have a valid file. – Bowelclose()
an open File Object before you can successfully callsetLastModified(time)
. In the case of anew File("xxxx.txt")
, if "xxxx.txt" refers to an actual file, you can callsetLastModified(time)
and it will change the time of the file. – Bowel