Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to clear the screen in java ?  RSS feed

 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can i clear the screen in a console based java program ? Like "cls" in DOS. I use jdk 1.6 and windows-7 64 bit home.
 
Mohamed Sanaulla
Bartender
Posts: 3179
34
Google App Engine Java Ruby
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This would depend on the type of terminal/console your java program runs. You would have to run an external command to achieve this. To run an external command- You can have a look at Runtime.exec(), but before that read this article about how and how not to use exec().
 
Ashish Schottky
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I know, cls in DOS, clrscr(); in C++ are all os dependent.In fact C++ is itself an os-dependent language. This is not the case with java. java uses bytecode logic(Google if you would like to know more) and thus is os-independent and hence doesnot allow os-dependent commands.
A simple means of clearing the screen is

can be used.
 
Campbell Ritchie
Marshal
Posts: 55678
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have an FAQ, but that might be out of date for Windows 7.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!