?
Solved

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

Posted on 2009-04-01
13
Medium Priority
?
6,235 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
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 150 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month15 days, 8 hours left to enroll

850 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