Clear screen In Java | Sololearn: Learn to code for FREE!


Clear screen In Java

how can I clear screen in Java? Just like clrscr(); in C language

4/8/2017 2:30:07 PM

Muhammad Ahmed

6 Answers

New Answer


System.out.print('\f'); or System.out.print('\u000C');


You can use ANSI escape control sequence: System.out.print("\u001B[2J"); ... will clear the screen ( without replacing text cursor at top left corner ^^ ) This should work on console ( real local ) but not with the console output emulator of Slolearn code playground :( [ edit ]


That doesn't work if you use your console to run your program. Works in ide.


I just needed this in Python*, and ANSI clear does not home the cursor to (0,0); it just prints enough blank lines to clear content...continuing at the bottom: [ (cleared area) [ [ [ content prints at bottom [ scrolling up_ The entire ANSI command string should be: chr(27) + "[2J" + chr(27) + "[0;0H" This clears the screen (2J) and positions the print cursor at the top left (0;0H) so it prints downwards. * (not Windows. Printing chr(12) usually clears those terminals)



not working :(