How to read a single char from the console in Java (as the user types it)?

后端 未结 5 1969
深忆病人
深忆病人 2020-11-21 05:49

Is there an easy way to read a single char from the console as the user is typing it in Java? Is it possible? I\'ve tried with these methods but they all wait for the user t

5条回答
  •  花落未央
    2020-11-21 06:16

    There is no portable way to read raw characters from a Java console.

    Some platform-dependent workarounds have been presented above. But to be really portable, you'd have to abandon console mode and use a windowing mode, e.g. AWT or Swing.

提交回复
热议问题