JavaRanch Home    
This page:         last edited 13 April 2009         What's Changed?         Edit

How To Clear The Console   

There are several alternatives. You can print a bunch of blank lines and push all the text off the screen that way. If you don't mind some degree of platform lock-in, you can use JNI to make a system call, which of course ties you to one specific platform. You may be able to use Runtime.exec() to execute an external command.

Another option which works on many platforms is to use ANSI terminal-control escape sequences. By merely printing a few special characters, you can clear a window, print colored text, and perform other nifty tricks on any platform that supports ANSI escape characters, which includes Linux, Mac OS/X, and Windows (if the ANSI.SYS driver is installed.)

A pure Java library for console control (which also supports color and other console options) is the JChassis ANSI Terminal Controller.

There is a Java Curses Library available for both Unix-like and Windows platforms (curses being a terminal library on Unix-like systems). This is a full-fledged AWT-like text console windowing toolkit including dialogs, lists, scrollbars and so on.

JavaRanchContact us — Copyright © 1998-2014 Paul Wheaton