Search This Blog

Friday, June 16, 2006

why Java classes direct program messages to the system console, but error messages to the file??

Hi Friends,
Today as usual I came to office and started my work. As I am in development have to write a code and then run it on the server.But today when I started my server I started Wondering why Java classes direct program messages to the system console, but error messages to the file (log files)?

I tried finding out solution for the same and after struggle of an hour I found the solution for the same. So I thought I will share this with you all and If I am wrong please Correct me .

Here is the Solution:
The class System has a variable out that represents the standard output, and the variable err that represent the standard error device. By default, they both point at the system console. This is how the standard output could be re-directed:

Stream st = new Stream (new FileOutputStream("output.txt"));
System.setOut(st);

And error redirect to the file.

System.setErr(st);

No comments: