Java UserPrincipal lookup user by name

Description

Java UserPrincipal lookup user by name


import java.io.IOException;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.attribute.UserPrincipal;
import java.nio.file.attribute.UserPrincipalLookupService;

public class Main {
  public static void main(String[] args) {
    FileSystem fs = FileSystems.getDefault();
    UserPrincipalLookupService upls = fs.getUserPrincipalLookupService();

    try {//from  w w  w . j a  v  a2s .  c om
      UserPrincipal user = upls.lookupPrincipalByName("yourName");
      System.out.format("User principal name is %s%n", user.getName());

    } catch (IOException e) {
      e.printStackTrace();
    }

  }
}



PreviousNext

Related