Getting file attributes in java

   try {
      // To get File metadata or File attributes. i.e file size , last modified date  we use below code

       Path file = FileSystems.getDefault().getPath("Examples", "Dir1","File1.txt");
       System.out.println("The size of file is "+Files.size(file));
       System.out.println("The file was last modified "+Files.getLastModifiedTime(file));

       //Another way to get all the arrtibutes of a file in one go is use the BasicFileAttributes class like below

       BasicFileAttributes attrs = Files.readAttributes(file,BasicFileAttributes.class);
       System.out.println("The size of file is "+ attrs.size());
       System.out.println("The file was last modified "+ attrs.lastModifiedTime());
       System.out.println("The file was created on  "+ attrs.creationTime());
       System.out.println("Is it a directory ? "+ attrs.isDirectory());
        System.out.println("Is it a regular file ?  "+ attrs.isRegularFile());
     }
       catch(IOException e){
           System.out.println(e.getMessage());
       }