I'm using Eclipse Helios and for some reasons i have to work with the console. I'm searching for a command which can clear my console at any time, while the program is running.
-
are you looking for a programmatic solution in java or just a button in the IDE? – Thomas Uhrig Sep 21 '11 at 07:16
-
1i would like something like System.out.println() but to clear the console – tgm Sep 21 '11 at 07:19
-
For eclipse console clearing --> multiple options are present.. u can doa simple rt click and clear , or u can set the preferrences to limit the console output.. i mean u can specify the number of lines et.. but if ur question is related to the console class in java..i dont think there is any clearing mechanism.. other than the flush api.. – Raveesh Sharma Sep 21 '11 at 07:19
-
This might help: https://stackoverflow.com/questions/9693124/override-previous-console-output or this: https://stackoverflow.com/questions/439799/whats-a-good-java-curses-like-library-for-terminal-applications – adam.r Jan 05 '14 at 20:50
-
1Does this answer your question? [Java: Clear the console](https://stackoverflow.com/questions/2979383/java-clear-the-console) – Grégori Fernandes de Lima Jul 11 '20 at 15:28
4 Answers
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)

- 2,785
- 2
- 13
- 10
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

- 519
- 4
- 15
public static void clear() {
for (int i = 0; i<30; i++){
System.out.print('\n');
}
}
I use this a lot

- 69
- 8
-
Its good, but I am very surprised given the age of Eclipse there is not something easier. – Andrew S Mar 24 '21 at 23:28
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
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.
For more information, you can see: https://www.eclipse.org/eclipse/news/4.14/platform.php

- 1,226
- 11
- 13
-
Please to provide more detail on how \b and \r can clear the console which is what the op asked for? – Andrew S Mar 24 '21 at 23:24