The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
April 2000



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.


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:\\ /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 (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


Sponsored Links

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