Modify file content without affecting created timestamp


I need to modify the content of a fairly simple json file without recreating the file each time. The reason is that I would like to keep the original time the file was first created. I've tried various approaches using both streams and channels but I cannot get it to work. The created file attribute is always updated.

This must be possible (right?) but apparently I am missing something.
Any thoughts?

Best regards
Daniel Södling
Daniel SödlingAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

What code are you using to modify the file contents?

Normally when we're writing files we just do it sequentially - which means you rewrite the file and really are deleting and creating a new one in its place.

If you want to modify the internals of the file without re-writing it, I think you may need to treat it as a RandomAccessFile:
which allows you to move around inside a file, rewrite portions of it and set its length.  It would require more care, should be possible to do what you need.  This should only change the "lastModified" time for the file, not when it was created.

George K.Commented:
I would simply read the attribute before any changes/before save,
then write it back after my modifications.
Nice George - I was aware you could change over file attributes but didn't realize creation time was one of them (interesting that you can have the file system essentially lie to you!).

Anyway the steps are here Daniel:


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Another possible approach is to move the file to a filesystem that doesn't support that attribute, such as Linux/Unix ext2/ext3
Daniel SödlingAuthor Commented:

thanks a bunch for your replies. I think the problem I'm seeing is related to the file system. I'm on Mac OS X and I'm guessing that it as a UNIX based system does not support the creation timestamp. At least not the retrieval of it from Java as I keep getting the last modified timestamp each time I ask for the creation time.

Thanks again to all of you
I think the problem I'm seeing is related to the file system. I'm on Mac OS X
HFS doesn't support file created. HFSPlus does in theory
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.