0

How do I clear the console in Java? This is my code but it doesn't do anything.

switch (commandTyped.toUpperCase()) {
        case "I":
            final String ANSI_CLS = "\u001b[2J";
            final String ANSI_HOME = "\u001b[H";
            System.out.print(ANSI_CLS + ANSI_HOME);
            System.out.flush();
            inventory.check();
            break;


    }

Thanks!

stephenpassero
  • 431
  • 1
  • 5
  • 16
  • Clearing the console (if it can be done at all) will be intimately tied to the particular Java execution environment you're using. – Ted Hopp Nov 23 '16 at 21:40

1 Answers1

-3

You can use:

Runtime.getRuntime().exec("cls");

it will clear the console

jrbedard
  • 3,662
  • 5
  • 30
  • 34
ZCoder
  • 2,155
  • 5
  • 25
  • 62