Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to clear screen (as clrscr in c) in java?

1,052 views
Skip to first unread message

vikaskumar sharma

unread,
Oct 6, 2012, 9:55:29 AM10/6/12
to
pls help me.if anyone knows how to clear screen of command prompt in
java as clrscr() in c language.

Jeff Higgins

unread,
Oct 6, 2012, 10:58:29 AM10/6/12
to
On 10/06/2012 09:55 AM, vikaskumar sharma wrote:
> pls help me.if anyone knows how to clear screen of command prompt in
> java as clrscr() in c language.
You'll need to call some system specific code.
Google java+clrscr.

Arne Vajhøj

unread,
Oct 6, 2012, 11:19:56 AM10/6/12
to
On 10/6/2012 9:55 AM, vikaskumar sharma wrote:
> pls help me.if anyone knows how to clear screen of command prompt in
> java as clrscr() in c language.

Use JNI to call clrscr.

Or use exex to call an external CLR command.

Arne


Jeff Higgins

unread,
Oct 6, 2012, 11:39:20 AM10/6/12
to
or java+curses

Jeff Higgins

unread,
Oct 6, 2012, 12:00:09 PM10/6/12
to
And after all that googling simply - don't do it.
Use a proper GUI - it may even look and feel like a text terminal.

Arne Vajhøj

unread,
Oct 6, 2012, 11:55:44 AM10/6/12
to
And that is good advice!

Arne


Real Gagnon

unread,
Oct 6, 2012, 12:11:44 PM10/6/12
to
> pls help me.if anyone knows how to clear screen of command prompt in
> java as clrscr() in c language.

One way is to use the Jansi library ( http://jansi.fusesource.org/ ).

See http://www.rgagnon.com/javadetails/java-0047.html

Bye.
--
Real Gagnon from Quebec, Canada
* Java, Javascript, VBScript or PowerBuilder snippets
* http://rgagnon.com/howto.html
* http://rgagnon.com/bigindex.html

Knute Johnson

unread,
Oct 6, 2012, 12:18:46 PM10/6/12
to
On 10/6/2012 6:55 AM, vikaskumar sharma wrote:
> pls help me.if anyone knows how to clear screen of command prompt in
> java as clrscr() in c language.
>

There is no similar method in Java. Windows has a command "cls" that
causes the DOS window to be cleared. It is an internal command specific
to Windows. Linux has a "clear" command which scrolls the window up to
clear it.

You could duplicate the Linux style clear command easily enough,
although I don't know of any way to determine how many lines the window
has. It may be possible to use Runtime.exec to issue these commands but
I've never been able to get it to work.

You should take a look at the Console class if you are going to do a
terminal based program.

--

Knute Johnson

Donkey Hottie

unread,
Oct 7, 2012, 7:14:35 AM10/7/12
to
Pressing ctrl+l from keyboard clears the Linux console. Maybe
System.out.print(CTRL_L); will do it? I did not test..

--

You have an unusual equipment for success. Be sure to use it properly.

Arne Vajhøj

unread,
Oct 7, 2012, 9:02:34 AM10/7/12
to
Very unlikely.

Typical there is a big difference between input and output.

It is 25 years since I have last seen a half duplex terminal.

Arne


Knute Johnson

unread,
Oct 7, 2012, 11:12:01 AM10/7/12
to
I haven't thought about one in at least that long :-).

--

Knute Johnson
0 new messages