Resetting Standard output Stream

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

Leave a Comment