You can get hold of the file descriptor for standard out through FileDescriptor.out
. To reset standard out to print to console, you do
System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
Another way is to simply hold on to the original object, as follows:
PrintStream stdout = System.out;
System.setOut(new PrintStream(logFile));
// ...
System.setOut(stdout); // reset to standard output
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…