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?
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?
I am using blueJ for java programming. There is a way to clear the screen of it's terminal window. Try this:-
this will clear whatever is printed before this line. But this does not work in command prompt.
I have successfully used the following:
NullStream
lives in theimport com.sun.tools.internal.xjc.util
package so might not be available on all Java implementations, but it's just anOutputStream
, should be simple enough to write your own.There are two different ways to clear the terminal in BlueJ. You can get BlueJ to automatically clear the terminal before every interactive method call. To do this, activate the 'Clear screen at method call' option in the 'Options' menu of the terminal. You can also clear the terminal programmatically from within your program. Printing a formfeed character (Unicode 000C) clears the BlueJ terminal, for example:
I found a solution for the wiping the console in an Eclipse IDE. It uses the Robot class. Please see code below and caption for explanation:
Assuming you haven't changed the default hot key settings in Eclipse and import those java classes, this should work.
System.out
is aPrintStream
, and in itself does not provide any way to modify what gets output. Depending on what is backing that object, you may or may not be able to modify it. For example, if you are redirectingSystem.out
to a log file, you may be able to modify that file after the fact. If it's going straight to a console, the text will disappear once it reaches the top of the console's buffer, but there's no way to mess with it programmatically.I'm not sure exactly what you're hoping to accomplish, but you may want to consider creating a proxy
PrintStream
to filter messages as they get output, instead of trying to remove them after the fact.You could print the backspace character
\b
as many times as the characters which were printed before.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?