问题
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