使用Java清除打印在命令行上的文本 [英] Clear text printed on the Command Line with Java
本文介绍了使用Java清除打印在命令行上的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何清除在Java命令行中打印的文本?我想在打印后清除 Text1
,然后使用 Text2
覆盖。我搜索并找到此代码,但它不工作。
How I can clear text that prints in command line with Java? I want to clear Text1
after prints and overwrite with Text2
. I search and find this code but it don't work.
public class className {
public static void main(String[] args) throws IOException {
System.out.println("Text1");
Runtime.getRuntime().exec("cls");
System.out.println("Text2");
}
}
推荐答案
可以打印 \b
:
System.out.print("Text1");
System.out.print("\b\b\b\b\b");
System.out.print(" ");
请注意,这不会在 Eclipse控制台。
这篇关于使用Java清除打印在命令行上的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文