如何删除System.out.println()打印到控制台的内容? [英] How to delete stuff printed to console by System.out.println()?

查看:143
本文介绍了如何删除System.out.println()打印到控制台的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java应用程序中,我正在使用一些调用 System.out.println()。现在我想找到一种以编程方式删除这些内容的方法。

In a Java application I'm using some calls to System.out.println(). Now I want to find a way to programmatically delete this stuff.

我找不到谷歌的任何解决方案,所以有任何提示吗?

I couldn't find any solution with google, so are there any hints?

推荐答案

您可以打印退格字符 \b 与打印的字符一样多次之前。

You could print the backspace character \b as many times as the characters which were printed before.

System.out.print("hello");
Thread.sleep(1000); // Just to give the user a chance to see "hello".
System.out.print("\b\b\b\b\b");
System.out.print("world");

注意:在Mars(4.5)之前的旧版本中,这在Eclipse控制台中无法正常工作。但这在命令控制台中非常好用。另请参见如何使退格\ b工作Eclipse的控制台?

Note: this doesn't work flawlessly in Eclipse console in older releases before Mars (4.5). This works however perfectly fine in command console. See also How to get backspace \b to work in Eclipse's console?

这篇关于如何删除System.out.println()打印到控制台的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆