Java tutorial
import java.io.PrintStream; import java.io.FileOutputStream; import java.io.File; public class Main { public static void main(String[] args) throws Exception { File outFile = new File("stdout.txt"); PrintStream ps = new PrintStream(new FileOutputStream(outFile)); System.out.println(outFile.getAbsolutePath()); System.setOut(ps); System.out.println("Hello world!"); System.out.println("Java I/O is cool!"); } }