This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I tried this out. If you call setLastModified before actually creating the file, it is not setting it correctly. Where in if you call setLastModified after creating the file, it is working. I tried this in Jdk 1.5 in Windows XP.
If other users are reading the file before you're done creating it, you need to prevent them from doing that. The usual way to achieve this is to create the file somewhere else, preferably in a direcory other users do not have access to, or which they don't know about or which they know not to look into. File.createTemporaryFile() is one way to do this. Once you have completely copied the file (closing the streams) and set its last modified time, then you use File.renameTo() to move the file to a new directory and new name. (Your temporary directory will probably need to be apart of the same filesystem as the intended target directory for this to work.) When the file appears in the new directory, it is ready to be seen by other users. [ January 07, 2006: Message edited by: Jim Yingst ]