0

I would like to know if it is possible in Java to hide all Console-Print-Outs for a certain amount of lines or time.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
51m0n
  • 13
  • 2

1 Answers1

1

"Java console output" is actually written to java.System.out.

If you wanted to "stop output" for some period, you could could temporarily "redirect" System.out to a dummy stream; some stream that doesn't write anything.

Look here: Hiding System.out.print calls of a class

System.out.println("NOW YOU CAN SEE ME");

PrintStream originalStream = System.out;

PrintStream dummyStream = new PrintStream(new OutputStream(){
    public void write(int b) {
        // NO-OP
    }
});

System.setOut(dummyStream);
System.out.println("NOW YOU CAN NOT");

System.setOut(originalStream);
System.out.println("NOW YOU CAN SEE ME AGAIN");
paulsm4
  • 114,292
  • 17
  • 138
  • 190