A quick and easy way to direct Java System.out to File and to Console





0/5 (0 vote)
try{ FileOutputStream fout= new FileOutputStream("stdout.log"); FileOutputStream ferr= new FileOutputStream("stderr.log"); TeeOutputStream multiOut= new TeeOutputStream(System.out, fout); TeeOutputStream multiErr= new TeeOutputStream(System.err, ferr); ...
try
{
FileOutputStream fout= new FileOutputStream("stdout.log");
FileOutputStream ferr= new FileOutputStream("stderr.log");
TeeOutputStream multiOut= new TeeOutputStream(System.out, fout);
TeeOutputStream multiErr= new TeeOutputStream(System.err, ferr);
PrintStream stdout= new PrintStream(multiOut);
PrintStream stderr= new PrintStream(multiErr);
System.setOut(stdout);
System.setErr(stderr);
}
catch (FileNotFoundException ex)
{
//Could not create/open the file
}