What is the best way to move/copy file while maintaining all its attributes (Date created, Date, etc)?
Thank you
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you are using Java 7, use
java.nio.file.Files.copy(Path source, Path target, CopyOption... options)Use the COPY_ATTRIBUTES option to maintain the last modified time:
Emphasis added
For Java 6 and earlier, Apache commons has a function to copy files
Note the comments
This will only try to preserve the modified date, and not other file attributes.
Otherwise, you will have to use Runtime.exec or something similar to run an external process.