Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Ankit Thakkar
Ranch Hand
Posts: 33
Android Java Mac PPC
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Santhosh Kumar
Ranch Hand
Posts: 242
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ankit Thakkar
Ranch Hand
Posts: 33
Android Java Mac PPC
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ankit Thakkar
Ranch Hand
Posts: 33
Android Java Mac PPC
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx JIM
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic