Get created file date java
Add a comment. Active Oldest Votes. Improve this answer. This would be best, but it is Java 7. We are still using 6, but I will investigate our upgrade options. Hooli No worries, mate! Try this logicbig. File creation date is not available on JDK 8 at least since statx syscall was added in newer Linux kernel version.
But why the creation time is always the same as the last modified time? File; import java. IOException; import java. Files; import java. Path; import java. BasicFileAttributes; import java. Date; import java. Oleksandr Tarasenko Oleksandr Tarasenko 1 1 gold badge 7 7 silver badges 14 14 bronze badges.
David Nugent David Nugent 4 4 silver badges 7 7 bronze badges. Do you know how to do it for Android? This is indeed true, even a call to stat doesn't work. Unless you happen to run a kernel higher than 4.
See related answer unix. Jorgesys Jorgesys k 22 22 gold badges silver badges bronze badges. People looking to use this class should note that it started shipping in Java 1.
Carl Smotricz Carl Smotricz Yeah, Java 7 would be great as the nio appears to have this in basic attributes. Never thought I would complain about being born too early! The reason the File class doesn't have this capability is that most filesystems don't even track this information.
And those that do don't always agree on when it should be updated. Syntactic: Actually most filesystems do track this information. But it has been slow to propagate through all the layers of Linux and the libraries and commands to make it universally used. Is it the normal behaviour? JayeshDhandha, if nothing modifies the file after it's created, I would expect creation and modification times to be equal.
You could try changing that by using touch to change the mod time and then checking again. Show 1 more comment. Jacek S Jacek S 2 2 gold badges 5 5 silver badges 11 11 bronze badges. Any other way around for linux machines which doesn't support created time?
Just use a file system that does support file creation timestamps. The Wikipedia article linked suggests ext4 which is quite common now. Thanks — Kirill Karmazin. Sign up or log in Sign up using Google.
Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Helping communities build their own LTE networks. Podcast Making Agile work for data science. Featured on Meta. Mostly, these methods will delegate to the associated file system provider to perform the file operations. BasicFileAttributes holds basic file attributes. These are attributes that are common to many file systems and consist of mandatory and optional file attributes, such as size of file creation time.
BasicFileAttributes are retrieved with Files. The file creation time in Java is retrieved with BasicFileAttributes. The BasicFileAttributes.
0コメント