使用FileSystem类的getUserPrincipalLookupService方法获取类的实例
import java.io.IOException; import java.nio.file.FileSystems; import java.nio.file.attribute.GroupPrincipal; import java.nio.file.attribute.UserPrincipal;/**NowJava.com - 时 代 Java**/ import java.nio.file.attribute.UserPrincipalLookupService; public class Main { public static void main(String[] args) { try { UserPrincipalLookupService lookupService = FileSystems.getDefault() .getUserPrincipalLookupService(); GroupPrincipal groupPrincipal = lookupService .lookupPrincipalByGroupName("Administrators"); UserPrincipal userPrincipal = lookupService/*from n o w j a v a . c o m*/ .lookupPrincipalByName("Richard");