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
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
精彩评论