0
How to clear screen in JAVA?
6 odpowiedzi
0
The correct answer would be by just typing System.out.println("\f");
+ 2
Prabhat Ranjan Form feed char ("\f" or "\x0c") was initialy intended for printers... It's highly dependent on the target console / device: how it's handled will vary and some might ignore it, others print one or a few blank lines.
For example, under my LMDE (Linux Mint Debian Edition) and python (2 & 3), print('\n',end='') output only one (almost empty) line (and doesn't simulate a cleared screen by printing enough lines to make the screen empty), as if I was printint a new line char ('\n') ^^
However, even if Form feed is working for you, that means that next prints will occurs at bottom of the screen, without reinitializing the cursor position to top left corner ;)
+ 1
in CLI environments, use the ANSI escape code, and more precisely the CSI (Control Sequence Introduction): CSI J
https://en.m.wikipedia.org/wiki/ANSI_escape_code
in GUI environments, you must refer to your GUI framework documentation ^^
+ 1
I guess that ncurses c-library should have a java binding: it's a useful library (tested with python) for handling advanced terminal output cross-platform/terminal:
https://en.m.wikipedia.org/wiki/Ncurses
That's not really a basic tool, but not really an obscure one: you need to deal with a relatively low-level API ;)
0
No you are wrong