Gente, como funciona a classe ProcessBuilder? E o Runtime?

0 respostas
java
Gabriel432135

Eu tava procurando um jeito de limpar a tela do cmd, e vi isso:

public static void main(String[] args) throws IOException, InterruptedException {

Scanner scanner = new Scanner(System.in);

System.out.println(Teste);

String texto = scanner.next();
//Limpa a tela no windows, no linux e no MacOS
    if (System.getProperty("os.name").contains("Windows"))
        new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
    else
        Runtime.getRuntime().exec("clear");

}

Como eles funcionam? Pra que serve o inheritIO();? O .start(); e o waitFor();?

Criado 4 de maio de 2020
Respostas 0
Participantes 1