1- this is OS specific! so not portable. In DOS, use "cls"; in UNIX "tput clear".
2- so use the Runtime class to pass the appropriate OS command to the OS. In the little sample it clear a UNIX screen clear.
/*
** Cmd - used to run a unix command and get the result back
*/
Code:
import java.io.*;
public class Cmd {
public static void main(String[] args) {
try {
String cmd = "/usr/bin/tput clear";
String line;
Process p = Runtime.getRuntime().exec(cmd);
BufferedReader input = new BufferedReader
(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
System.out.print(line);
}
input.close();
} catch (Exception err) {
err.printStackTrace();
System.exit( 100 );
}
return;
}
}