We are going to explore in a nutshell, one of the most advanced and important files attribute views which is User-Defined File Attributes View.
Particularly, I am using this feature a lot in my exchanged files during integration between my systems, to hide my files meta-data and security related information from users and contents of the file. So the file content will be only regarding the content of the file only, no more irrelevant meta-data.
Therefore If you find that there are not enough built-in attributes for your needs or if you have some unique meta-data (meaningful to the file system) that you want to associate with a file, you can define your own attributes.
NIO.2 offers the user-defined file attributes view, extended attributes through the UserDefinedFileAttributeView
interface. This facility allows you to associate to a file any attribute that you consider to be useful for your use cases.
Here you should know how to:
- Check User-Defined Attributes Supportability
- Operations on User-Defined Attributes as the following:
- Define a User Attribute.
- List User-Defined Attribute Names and Value Sizes.
- Get the Value of a User-Defined Attribute.
- Delete a File’s User-Defined Attribute.
Here is the class that has operations defined previously, also you need to use JDK 7+:
- JavaSE 7,8: Determining Views Supported by a Particular File System
- JSR 203: More New I/O APIs for the JavaTM Platform ("NIO.2")
- Java SE tutorial: File I/O (Featuring NIO.2)