commands in java to clear the screen

I think what the OP wants is to clear the screen and move the cursor to the home position. For that try:

        final String ANSI_CLS = "\u001b[2J";
        final String ANSI_HOME = "\u001b[H";
        System.out.print(ANSI_CLS + ANSI_HOME);
        System.out.flush();

It depends on your console but if it supports ANSI escape sequences, then try this..

final static String ESC = "\033[";
System.out.print(ESC + "2J"); 

Leave a Comment