Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Clear Screen in java?

 
Prateek Rawal
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider the following code:


The output of the code is:
1
2
3
4
5
6
7
8
9
10

I want the screen to get clear everytime the loop runs, although in this case it seems silly but for example i can create a new thread,make it print something and ask it to sleep, and when it wakes up i want the screen to get clear(so that i can notice the difference before clearing the screen and after clearing the screen......

So, speaking directly, i want the way to clear the screen in java.....


 
Ankit Garg
Sheriff
Posts: 9529
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check this FAQ...
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no simple way to do that. You might want to take a look at the link that Ankit posted. However do not go for an overkill like using another library to clear your screen. May be what you need is a method that will print 100 blank lines and you can invoke this method whenever required.
 
Prateek Rawal
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no simple way to do that.


So you are saying that there is no method or way in Java by which i can clear the screen anytime,
thats a shocking fact....omg!!!
 
Mark Uppeteer
Ranch Hand
Posts: 159
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I once asked myself the same question (back in the days I was mostly doing C and C++) and was also shocked to hear that. But nowadays I'm not anymore and find it normal.


anyway..
try this:


in dos and read this


but you don't need to know this for your SCJP you know.
 
Prateek Rawal
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The above supposed-to-be-solution is not working, i'm getting output like this

<-[2J
1
<-[2J
2
<-[2J
3
...and so on

Is clear screen not possible in java?
Give me a definite answer, i'm not able to interpret from the link you gave me....
Can you explain it here itself?


 
Dieter Quickfend
Bartender
Posts: 543
4
Java Netbeans IDE Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As was stated before, clear screen doesn't depend on any programming language, it depends on an Operating system. Read Mark Uppeteer's link. The only reason clear screen doesn't work in Java is because Java is platform independent and consoles are bound to the platform.

So you're not to check java for a clear screen command, you're to check your console if it allows it, then in what way it allows it.
 
Prateek Rawal
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm doing my program on command prompt....
How can i get how to clear screen in cmd using java?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic