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.
Thanks Santosh U r right, But I am setting file time for network pc's so if that file has been opened by another user then I am not able to set the file time
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 ]