Obtaining a map of file attributes - Java File Path IO

Java examples for File Path IO:File Attribute

Description

Obtaining a map of file attributes

Demo Code

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
import java.util.Set;

public class Main {
  public static void main(String[] args) throws Exception {
    Path path = Paths.get("/home/docs/users.txt");

    Map<String, Object> attrsMap = Files.readAttributes(path, "*");
    Set<String> keys = attrsMap.keySet();

    for (String attribute : keys) {
      System.out/*from   w w  w . j av a2 s . c o m*/
          .println(attribute + ": " + Files.getAttribute(path, attribute));
    }
  }

}

Related Tutorials