Close

Find file creation date

[Updated: Dec 7, 2016, Created: Aug 25, 2016]

Java Java Date Time 

Files.readAttributes() gets instance of BasicFileAttributes which encapsulates a set of file attributes which are common to different O.S. file system. These attributes include file type, creation time, last modified time, symbolic link info etc.

package com.logicbig.example;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.attribute.BasicFileAttributes;
import java.time.LocalDateTime;
import java.time.ZoneId;

public class CreationDateExample {

public static LocalDateTime getCreationDateTime (File file) throws IOException {

BasicFileAttributes attr = Files.readAttributes(file.toPath(),
BasicFileAttributes.class);
return attr.creationTime()
.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDateTime();
}

}


See Also