What about System.setOut(PrintStream)
? You could insert this call in the initialization part of your program (start-up).
Was previously a commment:
And of course you can do the same with System.err - namely System.setErr(PrintStream), but better to a different file stream.
In detail assuming an autoflushing appending and buffered file stream:
String file = ...;
PrintStream ps =
new PrintStream(true, new BufferedOutputStream(new FileOutputStream(file, true)));
System.setOut(ps);