Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I have a more example of FileAttribute?

Tags:

java

io

nio

Basically in the Files.createFile(Path fileName, FileAttribute<?>... attrs ); there is the possibility to insert a series of attributes. I am aware of the following possibility:

Path path = Paths.get(path...);//the file path


PosixFileAttributes attr = Files.readAttributes(path,PosixFileAttributes.class);
Set<PosixFilePermission> permissions = attr.permissions();
FileAttribute<Set<PosixFilePermission>> attra 
                            = PosixFilePermissions.asFileAttribute(permissions);
Files.createFile(path,attra);

Do you know any other real life application of the createFile() method? And with other application I mean other attributes passed as a FileAttribute parameter other than a set of PosixFilePermission? What are other "passable" FileAttribute parameter that I can use to create a new file with File.createFile(path, attr); ? Thanks in advance.

like image 987
Rollerball Avatar asked Nov 03 '22 22:11

Rollerball


1 Answers

Yes, the Access Control Lists (ACL) attributes.

See Java 7 Documentation for AclFileAttributeView for how to use them with createFile and createDirectory methods.

like image 191
Grzegorz Żur Avatar answered Nov 09 '22 04:11

Grzegorz Żur