Search code examples
javascreencls

Need some kind of Clearscreen for Java


Just like we have the clear screen in C/C++... Is there a way to do the same in Java? I've looked everywhere and found nothing at all.

I am trying to use it to update what a program shows every second, getting rid of all the code that appeared before. If you know of any other way to do this, I would really appreciate it

Thanks :)


Solution

  • Below is the code sample which works in command prompt

    import java.io.*;
    public class ClearDemo
    {
     public static void main(String args[])throws IOException,InterruptedException
     {
      System.out.println("Hello ,this is test program");
     new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
     }
    }