Close

Java IO & NIO - Files.getAttribute() Examples

Java IO & NIO Java Java API 


Class:

java.nio.file.Files

java.lang.Objectjava.lang.Objectjava.nio.file.Filesjava.nio.file.FilesLogicBig

Method:

public static Object getAttribute(Path path,
                                  String attribute,
                                  LinkOption... options)
                           throws IOException

Reads the value of a file attribute.

The format of the attribute must be of [view-name:]attribute-name form, where square brackets [...] represents an optional component. For example basic which corresponds to the name of the file attribute view BasicFileAttributeView. The right side part attribute-name is the name of the attribute. Other sub-classes of BasicFileAttributeView can also be used.

Parameters:
path - the path to the file
attribute - the attribute to read
options - options indicating how symbolic links are handled
Returns:
the attribute value


Examples


package com.logicbig.example.files;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

public class GetAttributeExample {

public static void main(String... args) throws IOException {
Path tempFile = Files.createTempFile("test-file", ".txt");
Object attribute = Files.getAttribute(tempFile, "basic:creationTime");
System.out.println(attribute);
Object readOnly = Files.getAttribute(tempFile, "dos:readonly");
System.out.println(readOnly);
}
}

Output

2017-12-11T03:41:19.264013Z
false




See Also