I\'m trying to intercept System.out and System.err, but maintain the ability to write to the original streams directly when necessary.
PrintStream ps = Syste
Try something like this :
PrintStream original = new PrintStream(System.out);
// replace the System.out, here I redirect to NUL
System.setOut(new PrintStream(new FileOutputStream("NUL:")));
System.out.println("bar"); // no output
// the original stream is still available
original.println("foo"); // output to stdout