Question:
How do you Clear the Console in Java?
2011-10-14 02:08:06 UTC
Im just using the windows command prompt. How can I clear the console ON WINDOWS 7 without printing a bunch of random lines like a retard?
Four answers:
2011-10-14 02:51:09 UTC
Hi,



Java is intended to be a cross platform code capable of working on any Operating system and thus does not assume standard out is a console.



Therefore, there is not built in method in the System heirarchy intended to clear it.



You could use the Runtime.exec("cls") command but this again is OS dependent, and thus wont work in all operating systems.



You'd be better off using GUIs which do have purpose built methods to clear the screen.



If you want to clear the console, you have to be making an assumption there is one. To make that assumption means you no longer have a cross platform programming code!



Regards,



Javalad
2016-05-16 07:42:10 UTC
You can't backspace or flush any of the Java consoles. In Windoze you can't even show Unicode characters. If you want a blank screen, you use "\n\n\n\n\n\n\n\n\...
Casper
2011-10-14 02:09:42 UTC
type cls and press enter
Harriet
2014-11-09 09:51:28 UTC
cls


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...