Java examples for File Path IO:File System
Get instance of class using the FileSystem class' getUserPrincipalLookupService method
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(); } } }