what is the command in java to clear console screen output?

Hi

I have a console program written by java 1.5, it will display data when the input parameters change. However, I want to clear the screen and display new data.

What is the java code to clear the console screen?

techquesAsked:
Who is Participating?
 
Thomas4019Commented:
Yes, I am fairly sure that wouldnt not work becuse that executes that command in a different process and in a hidden window.

Here's a link looking into ways to do what you want.

http://faq.javaranch.com/java/HowToClearTheConsole
0
 
ksivananthCommented:
I think, the easy way is to print empty lines!
0
 
VenabiliCommented:
Nothing in the language (that I know about).
When I need it I use the OS level commands - check for OS and invoke the proper one.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
VenabiliCommented:
>>the easy way is to print empty lines!
Won't this end up with you being at the bottom of the screen and your input starting from somewhere in mid-screen? Not that it is a bad idea per se - just wondering ;)
0
 
ksivananthCommented:
>>Won't this end up with you being at the bottom of the screen and your input starting from somewhere in mid-screen

true, it would!
0
 
techquesAuthor Commented:
check for OS and invoke the proper one

It runs on windows os (2000 and xp), how should it be?

0
 
VenabiliCommented:
If it will run only on Windows

Runtime.getRuntime().exec("cls") or something like this should do the trick.
0
 
VenabiliCommented:
If you have issues with it on XP (seem to remember some but have no XP here now), you can also use "cmd /c cls" as a command.
0
 
ksivananthCommented:
>>check for OS and invoke the proper one

I don't think you can do that unless if there is a possibility with JNI/devicedriver but I doubt that but I would prefer you luanch your own console using Swing and then play there!
0
 
CEHJCommented:
You can't control the console from pure Java. If you want more control, use JCurses
0
 
Thomas4019Commented:
I would print around 30 empty lines to clear the screen. Print your infornation, then print a few more empty lines to bring the information up on the window.

So basically. Print 30 empty lines, Print information, Print 10 empty lines (Depends on window size).

I am fairly sure that all of these "Runtime.getRuntime().exec(....." commands will not work because though they are proper windows commands or console functions, how would Windows know which command prompt to run them in. So Windows runs them in a new process, bascically clearing the screen of a new window.
0
 
Tony O'ByrneSenior Web DeveloperCommented:
Is it even wise to use OS level commands?  If you use the OS level commands, do you basically destroy any chances of the application being cross-platform?
0
 
techquesAuthor Commented:
Runtime.getRuntime().exec("cls") does not work
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.