An alternative way of accessing file attributes is to use the Files
class' readAttributes
method. There are two overloaded versions of this method, and they differ in their second argument and their return data types. In this recipe, we will explore the version that returns a java.util.Map
object as it allows more flexibility in what attributes it can return. The second version of the method is discussed in a series of recipes, each devoted to a specific class of attributes.
To obtain a list of attributes in the form of a Map
object, the following steps need to be done:
1. Create a
Path
object representing a file.2. Apply the static
readAttributes
method against theFiles
class.3. Specify the value of its arguments:
The
Path
object representing the file of interestA
String
argument representing the attributes to be returnedAn optional third argument specifying whether symbolic links should be followed or not