Java FileSystem get user lookup service

Description

Java FileSystem get user lookup service


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  ww  w.  jav  a2s  . co m*/
      UserPrincipal user = upls.lookupPrincipalByName("yourName");
      System.out.format("User principal name is %s%n", user.getName());

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

  }
}



PreviousNext

Related