Solved

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

Posted on 2009-04-01
13
4,985 Views
Last Modified: 2013-12-22
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?

0
Comment
Question by:techques
  • 4
  • 3
  • 2
  • +3
13 Comments
 
LVL 26

Expert Comment

by:ksivananth
ID: 24039518
I think, the easy way is to print empty lines!
0
 
LVL 20

Expert Comment

by:Venabili
ID: 24039543
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
 
LVL 20

Expert Comment

by:Venabili
ID: 24039554
>>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
 
LVL 26

Expert Comment

by:ksivananth
ID: 24039723
>>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
 

Author Comment

by:techques
ID: 24039782
check for OS and invoke the proper one

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

0
 
LVL 20

Expert Comment

by:Venabili
ID: 24039883
If it will run only on Windows

Runtime.getRuntime().exec("cls") or something like this should do the trick.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 20

Expert Comment

by:Venabili
ID: 24039916
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
 
LVL 26

Expert Comment

by:ksivananth
ID: 24040022
>>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
 
LVL 86

Expert Comment

by:CEHJ
ID: 24040162
You can't control the console from pure Java. If you want more control, use JCurses
0
 
LVL 17

Expert Comment

by:Thomas4019
ID: 24044164
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
 
LVL 6

Expert Comment

by:Tony O'Byrne
ID: 24045352
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
 

Author Comment

by:techques
ID: 24069960
Runtime.getRuntime().exec("cls") does not work
0
 
LVL 17

Accepted Solution

by:
Thomas4019 earned 50 total points
ID: 24073568
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java Filesystem manipulation of Word Docx file (find replace text) 3 66
simple java question 3 44
custom annotations 9 32
egit plugin on eclipse 8 40
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now