Java: Clear the console -


can body please tell me code used clear screen in java? example in c++

system("cls"); 

what code used in java clear screen?

thanks!

since there several answers here showing non-working code windows, here clarification:

runtime.getruntime().exec("cls"); 

this command not work, 2 reasons:

  1. there no executable named cls.exe or cls.com in standard windows installation invoked via runtime.exec, well-known command cls builtin windows’ command line interpreter.

  2. when launching new process via runtime.exec, standard output gets redirected pipe initiating java process can read. when output of cls command gets redirected, doesn’t clear console.

to solve problem, have invoke command line interpreter (cmd) , tell execute command (/c cls) allows invoking builtin commands. further have directly connect output channel java process’ output channel, works starting java 7, using inheritio():

import java.io.ioexception;  public class cls {     public static void main(string... arg) throws ioexception, interruptedexception {         new processbuilder("cmd", "/c", "cls").inheritio().start().waitfor();     } } 

now when java process connected console, i.e. has been started command line without output redirection, clear console.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -