“Java Clear Console” Code-Antworten

Java Clear Console

public static void clearScreen() {
        System.out.print("\033[H\033[2J");
        System.out.flush();
    }
Nasty Narwhal

Java Clear Console

// in JDK 11 you can do:

// It can be better than exec("cls") because it even works in intellij.
// Also, putting println() in a for loop is worse because there is a
// noticable delay between calls. This code does a single call, but
// stacks a ton of '\n's.

private void clearConsole() {
	System.out.println(System.lineSeparator().repeat(100));
}
simondoesstuff

Java Clear Console

Runtime.getRuntime().exec("cls");
Nimorum

Java Clear Console

String[] cmd;
//checking for OS
if(System.getProperty("os.name").contains("win")){
	cmd=new String[]{"cmd", "/c", "cls"};
}else{
	cmd=new String[]{"cls"};
}
//clearing the screen
ProcessBuilder pb=new ProcessBuilder(cmd);
pb.redirectInput(ProcessBuilder.Redirect.INHERIT);
Process process=pb.start();
dan1st

Java Clear Console


Runtime.getRuntime().exec("cls");

Disturbed Dingo

Ähnliche Antworten wie “Java Clear Console”

Fragen ähnlich wie “Java Clear Console”

Weitere verwandte Antworten zu “Java Clear Console” auf Java

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen