简体   繁体   English

Java:在输出中显示更改的文本

[英]Java: Display changing text on output

Currently, my program prints to System.out : 目前,我的程序将打印到System.out

Processing line 1 of 3...
Processing line 2 of 3...
Processing line 3 of 3...

Is there any way to have it replace the line numbers, instead of printing a new line? 有什么办法可以代替行号,而不是打印新行?

Well there are some hacks you can try, but none of them are guaranteed to work everywhere. 好了,您可以尝试一些技巧,但是它们中的任何一种都不能保证在任何地方都能正常工作。 Escape characters such as \\b (backspace) can erase the last character and \\r (replace) can erase the last output. 转义字符,例如\\b (退格)可以擦除最后一个字符,而\\r (替换)可以擦除最后的输出。

It may or may not work (depending on IDE), but you could try: 它可能会或可能不会(取决于IDE),但是您可以尝试:

System.out.print("Hello");
Thread.sleep(1000);
System.out.print("\rWorld");

However, generally a Swing box should be used (dynamically updating GUI) to measure progress. 但是,通常应使用Swing框(动态更新GUI)来衡量进度。 See Progress Bars . 请参阅进度条

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM