Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8823563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:23:16+00:00 2026-06-14T06:23:16+00:00

In a Scala program I need to read from the standard input a password

  • 0

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 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:23:17+00:00Added an answer on June 14, 2026 at 6:23 am

    I assume you want to read the password from the console prompt, so you will need to create a Console instance from the System (Console is not a singleton).

    scala> val standardIn = System.console()
    standardIn: java.io.Console = java.io.Console@69d1964d
    
    scala> val password = standardIn.readPassword()
    

    Note that no import is necessary because of Scala’s type inference and the fact that System is already in scope by default.

    Consult the javadoc for java.io.Console for more info.

    EDIT: In a compiled Scala program:

    object ReadPassword {
      def main(args: Array[String]) {
        val standardIn = System.console()
        println("standardIn object: " + standardIn)
    
        print("Password> ")
        val pw = standardIn.readPassword()
    
        print("Password: ")
        pw.foreach(print) // For demonstration purposes
        println()
      }
    }
    

    Compiling/running:

    $ scalac ReadPassword.scala
    $ scala ReadPassword
    standardIn object: java.io.Console@311671b2
    Password> 
    Password: hello world
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have java API which return this type: ArrayList[ArrayList[String]] = Foo.someJavaMethod() In scala program,
I'm attempting to learn Scala coming from a Java background. Should the below program
scala> class A (s: String*) { val l: ListBuffer[String] = ListBuffer[String](s) } <console>:8: error:
I have written a short Scala program to read a large file, process it
Say, i have 1 CPU-intensive C++ console application(game server). Do i need to program
I started to program in Scala recently. I'm looking for a free Scala profiler.
I am using emacs to program in scala, now I installed ensime to be
The help menu of the Scala compiler (2.9.2) says -print Print program with Scala-specific
Will Java 8 support pattern matching like Scala and other functional programs do? I'm
Since Scala 2.7.2 there is something called Manifest which is a workaround for Java's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.