有没有一种方法,不使用任何类型的gui包,没有System.out将自己注入到提示符的中间?
该场景是一个线程程序,您可以在其中向服务器发送和接收消息。
在写入服务器时,您会收到来自服务器的消息。
“我正在写一封来自SERVERg的消息”
所以你基本上最终会在你的控制台中看到类似的内容。
有没有办法绕过这个问题并基本上将提示与输入分开?
答案 0 :(得分:2)
您可以执行以下操作来暂时缓冲输出:
ByteArrayOutputStream out = new ByteArrayOutputStream();
PrintStream oldOut = System.out;
System.setOut(new PrintStream(out));
// System.in read code
System.setOut(oldOut);
System.out.println(out.toString());
System.err