Use java.nio package for extracting the creation date and time of any file through java. To extract the date and time of the file use BasicFileAttributes class. java.nio package helps us to get the creation time, last access time and last modified time, it works for both file and directory.
- Import the necessary java libraries.
- Store the path of the file whose creation time we want.
- Create the path object and specify the path of the file into it.
- Then we have to create BasicFileAttributes class using the readAttributes() method.
- In readAttributes() method we have to pass two parameters which are path object and BasicFileAttributes class.
- Now we have to just call creationTime() method using attributes.
Below is the implementation to get the creation time of the file:
Below is the implementation to get the creation time of the file in the SimpleDateFormat:
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.