最佳答案
是否可以得到当前登录用户的名称(Windows/Unix)和机器的主机名?
我假设它只是某个静态环境类的属性。
我找到了这个用户名
com.sun.security.auth.module.NTSystem NTSystem = new
com.sun.security.auth.module.NTSystem();
System.out.println(NTSystem.getName());
还有这个机器的名字:
import java.net.InetAddress;
...
String computerName;
...
try {
computerName = InetAddress.getLocalHost().getHostName();
}
catch(Exception ex) {
...
}
第一个是专门为 Windows 设计的吗?
如果没有主机名集,第二个会做什么?