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
  • 304
  • 1
  • 5
  • 13
  • 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,494
  • 5
  • 27
  • 34
ZCoder
  • 1,851
  • 5
  • 21
  • 51