Java Files get single file attribute

Introduction

The following table lists the valid attribute names that can be used with getAttribute() method:

Attribute NameData Type
lastModifiedTime FileTime
lastAccessTimeFileTime
creationTime FileTime
size long
isRegularFile Boolean
isDirectory Boolean
isSymbolicLinkBoolean
isOther Boolean
fileKey Object
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;

public class Main {

   public static void main(String[] args) {
      try {//from   w  w  w . j a  v  a 2s  .c  o m
         Path path = FileSystems.getDefault().getPath("Main.java");
         System.out.println(Files.getAttribute(path, "size"));
      } catch (IOException ex) {
         System.out.println("IOException");
      }
   }
}



PreviousNext

Related