Determining the creation date of a file is crucial for tasks like organizing files by age. This article addresses a common question: "Is there a way to retrieve file creation dates in Java?"
According to the Java documentation, it's possible to access file metadata, including creation time, using Java's New I/O (NIO) library. Here's an example code snippet:
<code class="java">Path file = ...; BasicFileAttributes attr = Files.readAttributes(file.toPath(), BasicFileAttributes.class); System.out.println("creationTime: " + attr.creationTime());</code>
This code retrieves the creation time attribute of a file and prints it to the console.
Note that the availability of file creation time may vary depending on the underlying file system. It's recommended to check if the file system supports creation time metadata before attempting to access it.
The above is the detailed content of How Can I Retrieve File Creation Dates in Java?. For more information, please follow other related articles on the PHP Chinese website!