Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Copy files with Preserving Timestamp  RSS feed

 
Srinivas Katta
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I developed a Program to use Windows native commands from the Java to Copy Folders and files from one location to other location. Is there any way that I can preserve the Original file stamps for the files copied

Thanks
Srinivas
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am assuming you are making a system call to the windows "copy" command. my ten seconds of googling would indicate that no, it is not possible. the windows copy command seems to not support this option.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need to implement file copying by executing native Windows copy commands from Java.

Java has its own built-in methods to copy files, which are cross-platform (they work on any operating system that supports them, not just Windows). The class java.nio.file.Files contains a number of copy() methods, one of which takes two java.nio.Path objects and zero or more java.nio.file.CopyOption objects. When you specify CopyOption.COPY_ATTRIBUTES, Java will attempt to copy file attributes from the source to the destination file, including the last modified time of the file.

See the API documentation of Files.copy(Path, Path, CopyOption...)
 
Aaditya Singhania
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately windows haven't come up with a solution regarding this issue but there are several programs which claim to be able to preserve the creation date of files and obviously RoboCopy is an option to resolve the above issue. I've been a user of that myself, but has now been inconvenienced by several arbitrary error messages. Although I used to repeat the steps again and again taking care of everything, but I still used to get the same error. So the best among those few programs which surely will do the trick is GS RichCopy 360. The software provides allot of other features like e-mail notification when job is done, scheduling your copy etc. Its very robust and reliable. I've been using it myself from a long time. You must give it a try. Hope this might help.
 
Campbell Ritchie
Marshal
Posts: 55799
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I don't know whether the OP is still looking for a solution, but that sounds promising.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!