I have a simple piece of code that outputs console text to a text file in Java:
PrintStream out = new PrintStream(new FileOutputStream(\"test2_output.txt\"))
There is also a System.setErr() call to redirect stderr.
System.setErr()