How can we redirect the eclipse console output to a file? I can:
Run Configuration
->Commons
->Select a file
.
You can set the output of System.out programmatically by doing:
System.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream("/location/to/console.out")), true));
Edit:
Due to the fact that this solution is based on a PrintStream
, we can enable autoFlush, but according to the docs:
autoFlush - A boolean; if true, the output buffer will be flushed whenever a byte array is written, one of the println methods is invoked, or a newline character or byte ('\n') is written
So if a new line isn't written, remember to System.out.flush()
manually.
(Thanks Robert Tupelo-Schneck)