This tip shows how to redirect standard output (stdout) to a file.

 System.setOut(
    new PrintStream(
      new BufferedOutputStream(
        new FileOutputStream("output.dat"))));