Given a file and we have to get, print the file's owner name.
Following packages are using here, to implement this program,
- java.nio.file.*
- java.nio.file.attribute.*
There are following two important classes, which are using this program to get the file's owner name.
- FileOwnerAttributeView
- UserPrincipal
The method getOwner() gives the owner's name to the object of UserPrincipal class, which can be accessed through getName() method.
Program to get owner's name of a file in java
Output