How to handle java system.console () return null

I would like to get input from a console character from a character. So, for example, there is a string "input". If the current user input is "W", the input is "W", as the user continues to enter "h", the input is "Wh" and continues to "a" the input is "a". I used system.console () to accept inputs, but in eclipse it always returns null.

Is there a way to fix it or another way to handle a character with a character read from input?

Thanks!

+1
java input console
source share
1 answer

There is something you need to pay attention to: the System.console () method may return null. According to the API :

If the virtual machine is started from the interactive command line without redirecting standard input and output streams, then its console will exist and, as a rule, will be connected to the keyboard and display from which the virtual machine was started. If the virtual machine starts automatically, for example, using the background task scheduler, then usually there will be no console.

Try starting the application from the console / terminal / cmd.

+1
source share

All Articles