Forums Register Login

Regarding File Copy and make data & time same as source file

+Pie Number of slices to send: Send
I am trying to copy file on network pc's.
and I want date & time of copied file same as source file.
I am setting file date & time using file class.

***********************************

File sfile=new File();
File dfile=new File();

dfile.setLastmodified(sfile.getLastmodified());

************************************

But sometime I am getting date & time of copied file different than the source file.

Plz help me to solve this problem.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
Thanx JIM
Legend has it that if you rub the right tiny ad, a genie comes out.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1016 times.
Similar Threads
updating files from one repository to another
Locking of Files
Interesting Anomaly with toString() vs. Memory Address
Using HSSFWorkbook to copy excel file
Why Ant copy change the ownership of files
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 04:08:27.