System.out and System.err stream objects are mapped to ldquostandardrdquo output and error stream respectively. By default, Java display standard output/error on display console. Thus, when we print a statement using System.out System.out.printlnquotHello Worldquot System.err.printlnquoterrr.. Hello Worldquot It prints the messages to default console. What if you want to reassign the ldquostandardrdquo output and error stream Lets say you want to redirect all those standard out messages in a File. System class provides some useful API to re-assign ldquostandardrdquo input, output and error streams. setErrPrintStream err Reassigns the ldquostandardrdquo error output stream setInInputStream in Reassigns the ldquostandardrdquo input stream. setOutPrintStream out Reassigns the ldquostandardrdquo output stream. In below Java code we reassign ldquostandardrdquo output to a file and redirect all sysout messages to that file. System.out.printlnquotJanuaryquot System.out.printlnquotFebruaryquot PrintStream ps new PrintStreamquotC/sample.txtquot System.setOutps System.out.printlnquotMarchquot System.out.printlnquotAprilquot ps.close Output January February File sample.txt March April Thus only January and February will be displayed in console and March April will be printed in sample.txt file.