Solved

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

Posted on 2009-04-01
13
5,094 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

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…
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 will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

831 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