This tip will show the way to redirect the output of the System.out.println() to a file.

Java Code:
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;


public class RedirectOutputExp {

	public static void main(String[] args) {
		// Creates a file object
		File file = new File("C:\\MyFile.txt");
		try {
			// Creates and PrintStream Object for the File.
			PrintStream printStream = new PrintStream(file);
			// Redirect the output to the printStream.
			System.setOut(printStream);
			System.out.println("This is redirected output");
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

}