Hash code : 3. Timestamp after setting nanos : Instant Timespan : T Next Topic Java Timestamp. Reinforcement Learning. R Programming. React Native. Python Design Patterns. Python Pillow. Python Turtle. Verbal Ability. Interview Questions. Company Questions. Artificial Intelligence. Cloud Computing. Data Science. On Unix filesystems you cannot retrieve the creation timestamp, you simply get a copy of the last modification time. So sad, but unfortunately true.
I'm not sure why that is but the code specifically does that as the following will demonstrate. This is a basic example of how to get the creation date of a file in Java , using BasicFileAttributes class:.
The API of java. File only supports getting the last modified time. And the Internet is very quiet on this topic as well. Unless I missed something significant, the Java library as is up to but not yet including Java 7 does not include this capability.
Most of this work seems to be already done for you in a library called JNA , though. On a Windows system, you can use free FileTimes library.
This will be easier in the future with Java NIO. But remember that most Linux filesystems don't support file creation timestamps. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Determine file creation date in Java Ask Question.
Asked 11 years, 8 months ago. Active 3 months ago. Viewed k times. Community Bot 1 1 1 silver badge. Todd Todd 1, 2 2 gold badges 14 14 silver badges 18 18 bronze badges. Okay, after more discussions and investigations into the filesystems, we have decided that using last modified is sufficient since it would likely have to have been checked along with creation date. Both would need to be checked to determine whether an old file was recently modified and therefore still active.
So, just check for the file modified farthest in the past. Thanks for all the input. BTW, I would love to use nio, but the Linux flavor here doesn't support file creation anyway.
Add a comment. Active Oldest Votes. This would be best, but it is Java 7. We are still using 6, but I will investigate our upgrade options. Asked 10 years, 3 months ago. Active 2 months ago. Viewed k times. I want to name new files created by my Java application with the current timestamp. Jeff B 7, 16 16 gold badges 60 60 silver badges bronze badges.
What if multiple files are created at the same time? Is this an XY problem? What are you really trying to do? Add a comment. Active Oldest Votes. Derek Springer Derek Springer 2, 1 1 gold badge 13 13 silver badges 12 12 bronze badges. Nice simple line — Janath. Update: The terribly flawed date-time classes such as java.
Date , java. Calendar , and java. SimpleDateFormat are now legacy , supplanted by the java. Serge Seredenko 3, 7 7 gold badges 20 20 silver badges 37 37 bronze badges.
Abdul Basit Abdul Basit 1 1 silver badge 8 8 bronze badges.
0コメント