• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Copy files with Preserving Timestamp

 
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: 12085
29
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
Saloon Keeper
Posts: 15207
36
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...)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic