Java Files read attributes for attribute list

Introduction

String Attribute List
"basic:*" read all basic file attributes.
"*" read all basic file attributes.
"basic:size,lastModifiedTime" read the size and the last modified time of the basic view
"size,lastModifiedTime"read the size and the last modified time of the basic view
"acl:owner" read the owner attribute of a file using an ACL view
"posix:*"read all posix attributes of a file
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;

public class Main {
  public static void main(String[] args) throws IOException {
    // Get a Path object
    Path path = Paths.get("Main.java");

    // Prepare the attribute list
    String attribList = "basic:size,lastModifiedTime";

    // Read the attributes
    Map<String, Object> attribs = Files.readAttributes(path, attribList);

    // Display the attributes on the standard output
    System.out.println(attribs.get("size"));
    System.out.println(attribs.get("lastModifiedTime"));

  }/*from   ww  w.j a  v a  2 s .  com*/
}



PreviousNext

Related