Modify file content without affecting created timestamp

All,

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?
 
dpearsonCommented:
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:
http://thinktibits.blogspot.com/2012/12/Change-date-created-time-for-file-in-java-example-program.html

Doug
0
 
dpearsonCommented:
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:
http://docs.oracle.com/javase/7/docs/api/java/io/RandomAccessFile.html
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.

Doug
0
 
George K.Commented:
I would simply read the attribute before any changes/before save,
then write it back after my modifications.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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

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
Daniel
0
 
CEHJCommented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.