Close

Java IO & NIO - Files.getOwner() Examples

Java IO & NIO Java Java API 


Class:

java.nio.file.Files

java.lang.Objectjava.lang.Objectjava.nio.file.Filesjava.nio.file.FilesLogicBig

Method:

public static UserPrincipal getOwner(Path path,
                                     LinkOption... options)
                              throws IOException

Returns the owner of a file.

Parameters:
path - The path to the file
options - options indicating how symbolic links are handled
Returns:
A user principal representing the owner of the file


Examples


package com.logicbig.example.files;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.UserPrincipal;

public class GetOwnerExample {

public static void main(String... args) throws IOException {
Path tempFile = Files.createTempFile("test-file", ".txt");
UserPrincipal owner = Files.getOwner(tempFile);
System.out.println("owner: " + owner);
System.out.println("owner.name: " + owner.getName());
}
}

Output

owner: BUILTIN\Administrators (Alias)
owner.name: BUILTIN\Administrators




See Also