Java设置文件用户名和组

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/SonOfWind0311/article/details/85247415
    Files.createDirectories(dir.toPath());

    UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService();

    UserPrincipal user = lookupService.lookupPrincipalByName(sftpUser);
    Files.setOwner(dir.toPath(), user);

    GroupPrincipal group = lookupService.lookupPrincipalByGroupName("users");
    Files.getFileAttributeView(dir.toPath(), PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS).setGroup(group);

猜你喜欢

转载自blog.csdn.net/SonOfWind0311/article/details/85247415
今日推荐