Get instance of class using the FileSystem class' getUserPrincipalLookupService method - Java File Path IO

Java examples for File Path IO:File System

Description

Get instance of class using the FileSystem class' getUserPrincipalLookupService method

Demo Code

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

public class Main {
  public static void main(String[] args) {
    try {/*from  w  w w  .  jav a 2s . c o  m*/
      UserPrincipalLookupService lookupService = FileSystems.getDefault()
          .getUserPrincipalLookupService();
      GroupPrincipal groupPrincipal = lookupService
          .lookupPrincipalByGroupName("Administrators");
      UserPrincipal userPrincipal = lookupService
          .lookupPrincipalByName("Richard");
      System.out.println(groupPrincipal.getName());
      System.out.println(userPrincipal.getName());
    } catch (IOException e) {
      e.printStackTrace();
    }

  }
}

Related Tutorials