7

I wish to find the current username in scala.

On the command line I can do:

whoami 

In python, I can do:

import getpass
user_name = getpass.getuser()

How do I find the username in Scala?

Tzach Zohar
  • 37,442
  • 3
  • 79
  • 85
LearningSlowly
  • 8,641
  • 19
  • 55
  • 78

1 Answers1

13

You can use the Java API for this:

System.getProperty("user.name")

See more (Java) options here: Get login username in java

Community
  • 1
  • 1
Tzach Zohar
  • 37,442
  • 3
  • 79
  • 85
  • 1
    There is now also `scala.util.Properties.userName`, which may not have existed at the time of this answer. – ianpojman Apr 20 '22 at 15:57