Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6668305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:01:38+00:00 2026-05-26T03:01:38+00:00

What is the best way to move/copy file while maintaining all its attributes (Date

  • 0

What is the best way to move/copy file while maintaining all its attributes (Date created, Date, etc)?

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:01:39+00:00Added an answer on May 26, 2026 at 3:01 am

    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:

    COPY_ATTRIBUTES
    Attempts to copy the file attributes associated with this file to the
    target file. The exact file attributes that are copied is platform and
    file system dependent and therefore unspecified. Minimally, the
    last-modified-time is copied to the target file if supported by both
    the source and target file store
    . Copying of file timestamps may
    result in precision loss.

    Emphasis added

    For Java 6 and earlier, Apache commons has a function to copy files

        org.apache.commons.io.FileUtils.copyFile(File srcFile, File destFile,
    boolean preserveFileDate)
    

    Note the comments

    Setting preserveFileDate to true tries to preserve the file’s last
    modified date/times using File.setLastModified(long), however it is
    not guaranteed that the operation will succeed. If the modification
    operation fails, no indication is provided.

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What's the best/easiest/fastest way to move a project from a local copy to a
What's the best way to move a document from one doc library to another?
What is the best way to move around on a given very long command
What is the best way to authorize all users to one single page in
What's the best way to move a normal SQL server database to SQL Azure?
What is the best way to move database connective outside this class. So that
Best way i can demonstrate is by example, if you go here and move
What's the best way to move a Visual Sourcesafe repository to Mercurial (I'm interested
I'm trying to figure out the best way to move/merge a couple tables of
What is the best way to copy a string into a raw memory buffer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.