Is it possible to print text that can be edited by the user (for console programs)?

前端 未结 3 1313
小蘑菇
小蘑菇 2020-12-21 06:39

Say I allow the user to edit something, like the phone number in an Address Book (actually, that\'s exactly what I\'m doing). Is there something that I can add to println th

3条回答
  •  长情又很酷
    2020-12-21 07:07

    No, not using only what Java provides in the framework. Editing some text would require to

    1. act on key press, which is not possible as in Java the input is buffered (i.e., wait for Enter to be pressed)
    2. to move around in the text you output, which is also not possible

    This could be done using some native code (ncurse on linux, ...), using JNI or JNA, but not that easily.

    Note that there are some projects that aim to add those functionalities, so if you can use something outside of the core libraries, you could give them a tries... for instance http://code.google.com/p/java-console-api/

提交回复
热议问题