开发者

Clear eclipse console java [duplicate]

开发者 https://www.devze.com 2023-04-06 13:30 出处:网络
This question already has answers here: How to clear the console? (14 answers) Closed 2 years ago. I\'m using Eclipse Helios and for some reasons i have to work with the console. I\'m searc
This question already has answers here: How to clear the console? (14 answers) Closed 2 years ago.

I'm using Eclipse Helios and for some reasons i have to work with the console. I'm searchi开发者_如何学JAVAng for a command which can clear my console at any time, while the program is running.


Eclipse has a clear button for the console; that will be the only way to actually clear it. Your java app doesn't know about it's existence; the System.out is just shown there and if needed you can write data for the System.in. (Somewhat like a command shell)


you could try printing a bunch of newlines. Taking some code from someone else: System.out.println(new String(new char[70]).replace("\0", "\r\n"));

This will be a lot faster then a loop, becuase you only need to use System.out.println(); once


public static void clear() {
    for (int i = 0; i<30; i++){
       System.out.print('\n');
    }
}

I use this a lot


You can use control characters backslash (\b) and carriage return (\r). The Console view can interpret these controls, but it come disabled by default. For enable it you can go on Windows>Preferences and Run/Debug > Console and select Interpret ASCII control characteres

Clear eclipse console java [duplicate]

After these configurations, you can manage your console with control characters like:

\t - tab.

\b - backspace (a step backward in the text or deletion of a single character).

\n - new line.

\r - carriage return. ()

\f - form feed.

Clear eclipse console java [duplicate]

For more information, you can see: https://www.eclipse.org/eclipse/news/4.14/platform.php

0

精彩评论

暂无评论...
验证码 换一张
取 消