JDK-4466073 : File.setLastModified(long) is a little bit confusing
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.3.0
  • Priority: P5
  • Status: Closed
  • Resolution: Won't Fix
  • OS: solaris_8
  • CPU: sparc
  • Submitted: 2001-06-04
  • Updated: 2009-02-18
  • Resolved: 2009-02-18
Description
For java.io.File, it has a method setLastModified(long time), can it work exactly the same as the unix command "touch"? There is a slight difference. "touch" can change the timestamp of a file to the current time as long as the user has write permission to the file, while File.setLastModified(long time) requires the user to have an effective ID to be the same as the owner of the file. It's actually quite confusing to be different as "touch".
It can actually be fixed by passing a special time to setLastModified(long time) and passing eventually to the native code, so the native code can call utimes( const char* path, NULL) to have the same effect as Unix command "touch".

Comments
EVALUATION For compatability reasons, we can't change this method so that a special value means the current time. The new file system API (in jdk7) defines the setTimes method which does do what the submitter wants.
18-02-2009