aspose file tools*
The moose likes Java in General and the fly likes Copy files with Preserving Timestamp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Copy files with Preserving Timestamp" Watch "Copy files with Preserving Timestamp" New topic
Author

Copy files with Preserving Timestamp

Srinivas Katta
Ranch Hand

Joined: Feb 01, 2007
Posts: 76
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

Joined: Oct 02, 2003
Posts: 11407
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14269
    
  21

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...)


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Copy files with Preserving Timestamp