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
Clear dos windows
Posted by Erich Meuse on June 20, 2001 at 4:17 PM
From win95 I found the following code works:
Make sure ANSI.SYS is loaded from the config.sys file.
If the following line does not exist in the config.sys file
then you will have to add it and reboot your system before
the driver will be loaded.
char esc = 27; // ESC code
String clear = esc + "[2J" // note case
System.out.print(clear); // Dos screen should be cleared
> > I am trying to find out how to clear an msdos screen using java
> > In c++, there was a function called clrscr() which used to serve
> > this purpose - java does not seem to have anything similiar.
> > I have looked everywhere for a solution, and tried many different
> > suggestions none of which work.
> > For example...it was suggested to use ANSI terminal sequences,
> > but this failed..
> > also tried the following -
> > Runtime r = Runtime.getRuntime ();
> > Process p = r.exec ("cmd /c cls");
> > but what this was doing was clearing another thread - not the
> > main one i was working on.
> > I need a way of using the above to clear the main thread, or some
> > alternate suggestion of a solution that ppl might be aware of.
> > This is an urgent issue and would appreciate any and all assistance.
> > rgds.
> > Allan
> Allan, I am also having similar problems. Have you found a method of achieving the clearscreen yet? Would be grateful if you or anyone else could help. Thanks
> regards Ken.