The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
April 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Clearing the Screen in Java

Posted by Matt Gerrans on December 03, 2001 at 2:42 PM


> Try this to clear a console screen:
> System.out.print("\ 033c");

That didn't work for me; with the space after the backslash, it doesn't compile, without, it only printed a left-pointing arrow and a 'c' (maybe some information was lost or changed in the post?). If it did work, are you assuming the ANSI.SYS driver is loaded for this?

Anyway, I like a little color, even in my DOS boxes, so I do it this way:


Runtime.getRuntime().exec("c:\\command.com /c be cls bright white on blue");

That's using the old Batch Enhancer (be) Norton Utility. Works great an is aesthetically pleasing (well, as much as a DOS box can be).

I would prefer to use the COMSPEC environment variable instead of hard-coding Command.com (or cmd.exe), but for some reason, java.lang.System.getenv() has been deprecated and java.lang.System.getProperty() is an incomplete replacement (I don't know what they were thinking with this properties stuff, but for some silly reason it doesn't contain all the environment).

- mfg



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us