How to get Windows username in Java?

前端 未结 4 1788
别跟我提以往
别跟我提以往 2020-11-27 05:49

So what I am trying to do is let my Java find the user\'s name that windows is logged in with, so when I would say such a method, it would return the users name, like I use

4条回答
  •  猫巷女王i
    2020-11-27 06:16

    Try:

    String userName = System.getProperty("user.name");
    

    or

    String userName = new com.sun.security.auth.module.NTSystem().getName()
    

提交回复
热议问题