Wednesday, May 14, 2008

Redirecting Standard output and Standard error messages

In Java, the class ‘System’ contains two properties named ‘out’ and ‘err’, which represent the standard output and the standard error device, respectively.

By default, both of them point to the system console. But, using the exposed APIs you can redirect them to any output stream you want.

Stream customOutput = new Stream(new FileOutputStream(“custom_output.txt”));
Stream customError = new Stream(new FileOutputStream(“custom_error.txt”));

Redirection of the standard output and the standard error to custom streams can now be done as:-



No comments: