Java examples for File Path IO:File Owner
Get a File Owner Using Files.getAttribute()
import java.io.IOException; import java.nio.file.Files; import java.nio.file.LinkOption; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.attribute.UserPrincipal; public class Main { public static void main(String[] args) { Path path = Paths.get("C:/folder1/folder2/folder4", "test.txt"); try { UserPrincipal owner = (UserPrincipal) Files.getAttribute(path, "owner:owner",LinkOption.NOFOLLOW_LINKS); System.out.println(owner.getName()); } catch (IOException e) { System.err.println(e); } //from w ww . java 2 s.com } }
The file owner attribute can be required with the name: owner.
The generally accepted form is [view-name:]attribute-name.
The view-name is owner.