Yes, that is why the question contains a statement that asks you to assume that the file system on which the program is run does support this attribute.
It is possible to implement a file system that supports PosixFileAttributeView and also uses windows like paths. The program will run without any issues on it.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
In mala gupta book for OCP 7 in page 543 section 8.3.7 it is written that -
"To read or update the owner of a file or directory you can use
the AclFileAttributeView, FileOwnerAttributeView, and PosixFile-
Attribute interfaces." Is that wrong?
admin wrote:I can't really comment on that without knowing the context but did you try asking the author?
Paul.
No I didn't. While doing the enthuware mock exams, I found some conflicting memories as I read that book. And one more thing is that this was printed as 'exam tip'. So its straightforward, doesn't require a context. Would you post your independent opinion on this?
The get/setOwner are declared in FileOwnerAttributeView interface. This interface is extended by AclFileAttributeView and PosixFileAttributeView, and you can use those as well. So yes, the statement in the book looks correct.
I have updated the explanation of this question to include this fact.
-Paul.
If you like our products and services, please help us by posting your review here.
strangely enough i suspect enthuware being wrong here.
Let me explain:
In the explanation it is said that "The name of the method to get the owner of a File is owner and not getOwner. Note that this method returns an instance of java.nio.file.attributeUserPrincipal."
looking into https://docs.oracle.com/javase/7/docs/a ... Files.html it becomes clear that getOwner is the right method. Moreover, it returns not a attributeUserPrincipal (weird classname anyhow being not capitalized) but a UserPrincipal
This option is trying to apply the getOwner method on attrs, whose type is PosixFileAttributes. The explanation that you've quoted is associated with this option and is correct. To get the owner using PosixFileAttributes, the correct method name is owner() and not getOwner(). It returns java.nio.file.attribute.UserPrincipal. (The dot between attribute and UserPrincipal is missing.)
If you like our products and services, please help us by posting your review here.