Clear content from my netbeans java console

Asked

Viewed 10,404 times

3

Good morning guys, which java command do I use to clean up my netbeans console? Because I have a method that is every time printing some messages and I want you to keep cleaning this from my console.

3 answers

5

To clear the console, you can create and run the method below, which identifies the OS and executes the appropriate command to clear 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
        }
    }

NOTE: Adaptation of the original response published by the user Dyndrilliac in: https://stackoverflow.com/questions/2979383/java-clear-the-console

-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) {
    }
}
  • try to explain your answer...

-2

Try using the command first System.out.print ('\u000C');

  • What makes this command more specifically?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.