xxxxxxxxxx
public class ClearScreenExample {
public static void main(String[] args) {
clearScreen();
System.out.println("This is a test message.");
}
public static void clearScreen() {
try {
if (System.getProperty("os.name").contains("Windows")) {
new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
} else {
System.out.print("\033[H\033[2J");
System.out.flush();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}