Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java UserDefinedFileAttributeView

Tags:

java

nio

xattr

When I add a new UserDefinedFileAttributeView attribute to a file, where does Java store this information? There are no additional files in the directory, the file does not have any new attributes or details when I view the file properties.

My code:

String versionAttrName = "report.version";
try {           
    Path path = FileSystems.getDefault().getPath(filePath, "");
    UserDefinedFileAttributeView view = Files.getFileAttributeView(path, UserDefinedFileAttributeView.class);
    view.write(versionAttrName, Charset.defaultCharset().encode(newVersion));
} catch (IOException e) {
    System.out.println("7 - Error saving version to file! - "+ filePath + " - " + e.getMessage());
}
like image 316
gwin003 Avatar asked Apr 27 '26 02:04

gwin003


1 Answers

These metadata are stored using file system's "extended file attributes" (see wikipedia).

The list of file systems being supported is definitely JVM specific, so you should test in on all platforms you plan to support. But this answer lists some.

On linux, you can see these attributes using getfattr command:

$ getfattr -d test.txt
# file: test.txt
user.Name1="Value1"
user.Name2="Value2"
like image 135
Foyta Avatar answered Apr 28 '26 16:04

Foyta