OutputStream o = new ByteArrayOutputStream(); PrintStream out = new PrintStream(o); PrintStream obak = System.out; System.setOut(out); System.out.println("out something"); System.setOut(obak); System.out.println("other");