tags:

views:

161

answers:

2

I want to change modification timestamp of a binary file. What is the best way for doing this?

Would opening and closing the file be a good option? (I require a solution where the modification of the timestamp will be changed on every platform and JVM).

+3  A: 

I know Apache Ant has a Task which does just that.
See the source code of Touch (which can show you how they do it)

They use FILE_UTILS.setFileLastModified(file, modTime);, which uses ResourceUtils.setLastModified(new FileResource(file), time);, which uses a org.apache.tools.ant.types.resources.Touchable, implemented by org.apache.tools.ant.types.resources.FileResource...

Basically, it is a call to File.setLastModified(modTime).

VonC
+7  A: 

The File class has a setLastModified method. That is what ANT does.

Yishai