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());
}
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With