Clear contents of my netbeans console in java

3

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.

    
asked by anonymous 16.04.2015 / 16:38

3 answers

5

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

    
16.04.2015 / 17:54
-1
/**
 * 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) {
    }
}
    
06.10.2018 / 16:44
-2

Try to use the command System.out.print ('\u000C');

    
21.02.2018 / 00:01