Get file creation date

File meta data is stored within the file system and directories. It tracks information about each of the file which is typically referred to as file attributes. File attributes include size of a file, is it a directory, a symbolic link, a regular file, determine if the file is hidden, retrieve the last modified time and find when a file was created.

Setup

private static final String SOURCE = "com/levelup/java/io/get-file-creation-time.txt";

Path source;

@Before
public void setUp () throws IOException, URISyntaxException {

    source = Paths.get(this.getClass().getClassLoader().getResource(SOURCE).toURI());
}

Straight up Java

Java 7 File I/O

The BasicFileAttributes Javadoc states:

If the file system implementation does not support a time stamp to indicate the time when the file was created then this method returns an implementation specific default value, typically the last-modified-time or a FileTime representing the epoch (1970-01-01T00:00:00Z).

@Test
public void file_creation_time () throws IOException {

    BasicFileAttributes attr = Files.readAttributes(source, BasicFileAttributes.class);

    FileTime fileCreated = attr.creationTime();

    assertEquals(1389290887000l, fileCreated.toMillis());
}