Java Program to Get the Creation Time of a File Last Updated : 14 Sep, 2021 Comments Improve Suggest changes Like Article Like Report 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. Approach: 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: Java // Java program to get the creation time of a file import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.attribute.BasicFileAttributes; public class JavafileCreationTime { public static void main() throws IOException { // storing the path of the file in the variable String filename = "C:/Users/HARDSOL/Desktop/New folder (2)"; // creating the File class object File my_file = new File(filename); // creating the path object Path path = my_file.toPath(); // creating BasicFileAttributes class object using // readAttributes method BasicFileAttributes file_att = Files.readAttributes( path, BasicFileAttributes.class); // printing the file creation time by calling // creationTime() method System.out.printf("File Creation Time %s%n ", file_att.creationTime()); } } Output: Below is the implementation to get the creation time of the file in the SimpleDateFormat: Java // Java program to get the creation time of a file import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.attribute.BasicFileAttributes; import java.text.SimpleDateFormat; public class JavafileCreationTimee { public static void main() throws IOException { // storing the path of the file in the variable String filename = "C:/Users/HARDSOL/Desktop/New folder (2)"; // creating the File class object File my_file = new File(filename); // creating the path object Path path = my_file.toPath(); // creating BasicFileAttributes class object using // readAttributes method BasicFileAttributes file_att = Files.readAttributes( path, BasicFileAttributes.class); // creating simple date format object to make the // output more readable SimpleDateFormat sd = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); System.out.print("File Creation Time: "); // converting time to milliseconds then specifying // the format in which we want the output System.out.print( sd.format(file_att.creationTime().toMillis())); } } Output:  Comment More infoAdvertise with us Next Article Java Program to Get the Creation Time of a File srishivansh5404 Follow Improve Article Tags : Java Technical Scripter Java Programs Technical Scripter 2020 Java-Files +1 More Practice Tags : Java Similar Reads Java Program to Get the Basic File Attributes Basic File Attributes are the attributes that are associated with a file in a file system, these attributes are common to many file systems. In order to get the basic file attributes, we have to use the BasicFileAttributes interface. This interface is introduced in 2007 and is a part of the nio pack 3 min read Java Program to Create a Temporary File A File is an abstract path, it has no physical existence. It is only when "using" that File that the underlying physical storage is hit. When the file is getting created indirectly the abstract path is getting created. The file is one way, in which data will be stored as per requirement. Type of Fi 6 min read Java Program to Create a File with a Unique Name Java Programming provides a lot of packages for handling real-time problems but in our case, we need to create a File with a unique name. For this, there are different solutions in Java. Like Using timestamp series as the file name or creating a unique random number and then assigning that number as 6 min read Java Program to Create a File in a Specified Directory Creating a file in a specific directory using Java can be done in various ways. This is done using predefined packages and Classes. In this article, we will learn about how to create a file in a specified directory. Methods to Create a File in a Specified DirectoryThree such methods to create a file 3 min read Java Program to Change Last Modification Time of a File Modifying the date of the file is possible through Java using the File class of Java i.e File.setLastModified() method Java File Class The File class is Javaâs representation of a file or directory pathname. The File class contains several methods for working with the pathname, deleting and renaming 3 min read Like