Java console clearn?

1 Antwort

Da gibt es keine direkte Methode für, weil das plattformabhängig ist. Du kannst mit einem Workaround Windows und alles ANSI-kompatible wie Linux etc. bedienen, aber zum Beispiel in der Konsole der IDE geht das nicht:

public static void clearConsole() {
    try {
        if (System.getProperty("os.name").contains("Windows")) {
            new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
        }
        else {
            System.out.print("\033\143");
        }
    } catch (IOException | InterruptedException ex) {}
}
Woher ich das weiß:Berufserfahrung – Softwareentwickler & Admin