I would like to get input from the console character from character.

So for example, there's a String "input". If the current user input is "W", input is "W", as the user continues type in "h", input is "Wh" and continues "a" input is "a".

I used system.console() to accept the inputs but in eclipse it always return null.

Is there any way to fix it or there's another way to handle the character by character read from input?

Thanks!

解决方案

There is something you need to watch out for : The System.console() method can return null. According to the API:

If the virtual machine is started from an interactive command line without

redirecting the standard input and output streams then its console will exist and will typically be connected to the keyboard and display from which the virtual machine was launched. If the virtual machine is started automatically, for example by a background job scheduler, then it will typically not have a console.

Try to run your application from a console/terminal/cmd.

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐