Java Files read file attribute for BasicFileAttributes
import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.FileTime; public class Main { public static void main(String[] args) throws IOException { Path path = Paths.get("Main.java"); BasicFileAttributes bfa = Files.readAttributes(path, BasicFileAttributes.class); // Get the last modified time FileTime lastModifiedTime = bfa.lastModifiedTime(); System.out.println(lastModifiedTime); // Get the size of the file long size = bfa.size(); System.out.println(size);// w w w . ja v a 2s . c o m // Print some of the basic file attributes System.out.format("Size:%s bytes %n", bfa.size()); System.out.format("Creation Time:%s %n", bfa.creationTime()); System.out.format("Last Access Time:%s %n", bfa.lastAccessTime()); } }