1

I was trying to clear the console on java using the eclipse IDE and for some reason, the code isn't working how it is supposed to be working. I think it is something to do with me using eclipse and I am wondering if there is an alternative way to do the following code on eclipse.

System.out.print("\033[H\033[2J");  
System.out.flush();

the result I am getting from this code is...

[H[2J

if anyone knows away to get around this I will be happy to know.

tgkprog
  • 4,493
  • 4
  • 41
  • 70
Miqhtie
  • 63
  • 9
  • 3
    I don't think this has anything to do with `flush`. The console you're printing to doesn't seem to support ANSII escape codes (that complicated string you're trying to print out to do stuff). You'll need to use a different method or a different console. – Carcigenicate Nov 03 '19 at 18:52
  • Create a UTF-16 or other charset file and print there. Like above probably console does not support this charset – tgkprog Nov 03 '19 at 18:53
  • That code prints nothing on my IntelliJ IDEA console. – Sweeper Nov 03 '19 at 18:54
  • Yes Sweeper, that is what I am trying to make it do on my console. On IntelliJ if you were to print something before that then maybe do a Thread.sleep() it would print the original thing but then erase it. – Miqhtie Nov 03 '19 at 21:42

1 Answers1

1

Those are ANSI escape codes and they need support from the terminal. The standard terminal doesn't support them, but there are apparently plugins if you need that support (in Eclipse).

The flush() isn't related (or needed) in any way.

Kayaman
  • 72,141
  • 5
  • 83
  • 121