One of hundreds of answers available with our premium content service.
A: The java.lang.System class holds a static reference to the console output stream in its System.out field, which is an instance of java.io.PrintStream. The System.setOut(PrintStream) method allows you to assign a different output to the reference. In this case you can construct a PrintStream from a FileOutputStream, as below.
… full answer hidden
Premium members click below for full answer
How can I divert console output to a file?