Good morning, what command do I use in Java to clean the console of my netbeans? Well, I have a method that gets every x times printing some messages and I want it to be cleaning it from my console.
Good morning, what command do I use in Java to clean the console of my netbeans? Well, I have a method that gets every x times printing some messages and I want it to be cleaning it from my console.
To clean the console, you can create and execute the method below, which identifies the OS and performs the appropriate command to clean the console:
public final static void clearConsole(){
try{
final String os = System.getProperty("os.name");
if (os.contains("Windows")){
Runtime.getRuntime().exec("cls");
}else{
Runtime.getRuntime().exec("clear");
}
}
catch (final Exception e){
// Tratar Exceptions
}
}
OBS .: Adapt the original response posted by the user Dyndrilliac in: link
/**
* Função que limpa a Saída/Output do Netbeans
*/
public final static void limparSaida() {
try {
Robot robot = new Robot();
robot.setAutoDelay(10);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_L);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyRelease(KeyEvent.VK_L);
} catch (AWTException ex) {
}
}
Try to use the command System.out.print ('\u000C');