How do I touch a folder with current time using set last modified date & time?

  • A+
Category:Languages

I'm trying to update the last modified date of a specific folder, here's what I've got:

public void touchFolder(){     File folderToTest = new File("C://Temp");     SimpleDateFormat dateFormatUtc = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");     dateFormatUtc.setTimeZone(TimeZone.getTimeZone("UTC"));     String newTime = dateFormatUtc.format(new Date());     folderToTest.setLastModified(Long.parseLong(newTime)); } 

I am just putting this code in a test case so don't worry about calling this method etc.

I'm getting errors with the parsing that date format as a long, what's the format used in setting the last modified date & time?

 


This is an example from the documentation, using java.nio.file.Files:

Path path = ... FileTime now = FileTime.fromMillis(System.currentTimeMillis()); Files.setLastModifiedTime(path, now); 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: