Java: Clear the console

后端 未结 14 2697
青春惊慌失措
青春惊慌失措 2020-11-21 23:26

Can any body please tell me what code is used for clear screen in Java? For example in C++

system(\"CLS\");

What code is used in Java for

14条回答
  •  攒了一身酷
    2020-11-22 00:24

    Try this: only works on console, not in NetBeans integrated console.

        public static void cls(){
    try {
    
        if (System.getProperty("os.name").contains("Windows"))
            new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
        else
            Runtime.getRuntime().exec("clear");
    } catch (IOException | InterruptedException ex) {}
    

    }

提交回复
热议问题