In a Scala program I need to read from the standard input a password string (with echoing disabled). I tried with:
java.io.Console.readPassword
But for some reason I cannot invoke any methods in the java.io.Console object from Scala (?).
Which is the “standard” way to read a string (with echoing disabled) from the standard input in Scala ?
I assume you want to read the password from the console prompt, so you will need to create a
Consoleinstance from theSystem(Consoleis not a singleton).Note that no
importis necessary because of Scala’s type inference and the fact thatSystemis already in scope by default.Consult the javadoc for
java.io.Consolefor more info.EDIT: In a compiled Scala program:
Compiling/running: