有没有办法使用java在Linux机器上获取用户的UID?我知道System.getProperty("user.name");
方法,但它返回用户名,我正在寻找 UID。
你可以执行id
命令并读取结果。
例如:
$ id -u jigar
output:
1000
你可以通过以下方式执行命令
try {
String userName = System.getProperty("user.name");
String command = "id -u "+userName;
Process child = Runtime.getRuntime().exec(command);
// Get the input stream and read from it
InputStream in = child.getInputStream();
int c;
while ((c = in.read()) != -1) {
process((char)c);
}
in.close();
} catch (IOException e) {
}
source http://www.exampledepot.com/egs/java.lang/ReadFromCommand.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)