[英]Separating System.Out messages and Scanner (Java)
有没有办法,没有使用任何类型的gui包,没有System.out注入到你的提示中间?
该场景是一个线程程序,您可以在其中向服务器发送和接收消息。
写入服务器时,您会收到来自服务器的消息。
“我正在写一封来自SERVERg的消息”
所以你基本上最终会在你的控制台中看到类似的东西。
有没有办法绕过这个问题,并基本上将提示与输入分开?
您可以执行以下操作来缓冲输出临时:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.