如何使用java7文件属性api获取数字groupid/userid? [英] How to get numeric groupid/userid using java7 file attribute apis?

查看:74
本文介绍了如何使用java7文件属性api获取数字groupid/userid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用以下代码获取文件所有者的名称;

I can use the following code to get the name of the owner of a file;

    final PosixFileAttributes basicFileAttributes =
        Files.readAttributes( path, PosixFileAttributes.class, 
                                    LinkOption.NOFOLLOW_LINKS );
    String ownerName = basicFileAttributes.owner().getName();

但是我也试图获取有问题的用户的数字unix ID.在调试器中,我可以看到它隐藏在"UnixFileAttributes"(PosixFileAttributes的子类)中,但是有没有任何合理的标准方法来获取它?

But I'm also trying to get hold of the numeric unix id of the user in question. In the debugger I can see it's hiding inside "UnixFileAttributes" (subclass of PosixFileAttributes), but is there any reasonably standard way to get hold of it ?

推荐答案

实际上存在一个"unix"视图,您可以通过以下方式访问此类特定于Unix的属性:

There's actually a "unix" view you can get access to such Unix-specific attributes through:

int uid = (int) Files.getAttribute(path, "unix:uid", NOFOLLOW_LINKS);

这篇关于如何使用java7文件属性api获取数字groupid/userid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆