Java:确定当前Windows用户的程序化方法

jjn*_*guy 8 java windows

我看到很多类似的问题,但是我想找到使用Java的当前登录用户的用户名.

它可能类似于:

System.getProperty(current.user);
Run Code Online (Sandbox Code Playgroud)

但是,我不太确定.

Chr*_*nch 29

你真的很亲密.这就是你要找的东西:

System.getProperty("user.name")
Run Code Online (Sandbox Code Playgroud)


Joh*_*her 5

System.getProperties()方法中记录了常用的系统属性.

正如克里斯所说,"user.name"是让用户运行你的应用程序的属性.