Read user input without deleteing what they have written when console output in java [duplicate]

为君一笑 提交于 2020-01-17 14:03:10

问题


This is in a Java command line application. I am working on an application that will be constantly receiving data and then printing it. I also need to accept commands to send out the port. Every time I type something it gets moved up a line when the console outputs. Ideally I could have a prompt before the command. I have tried to grab the current input, delete it, then print the msg, and then reprint the input, but I could only grab input after the user pressed enter. I have spent a couple hours just googling trying to find the answer. I also have asked some people I know but still nothing.

I tried

scn = new Scanner(System.in); while(true) { System.out.println(scn.next()); }

but it does not fire until I press enter.

I also tried

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

but I got the same result

My goal: Have a command line in java with a prompt and when the system outputs it does not move the input up a line. If you have ever worked with a minecraft server console,

This has all the info you asked for... so PLEASE talk to me before closing it...

来源:https://stackoverflow.com/questions/59619867/read-user-input-without-deleteing-what-they-have-written-when-console-output-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!