Java’s
System class provides the static PrintStream fields out and err. By default both write to the console, but you can redirect them separately with setOut() and setErr(). Here’s how to send only error messages to a file while keeping standard output on the console:PrintStream errorStream = new PrintStream(new FileOutputStream("error.log"));
System.setErr(errorStream);
// System.out remains on the console
No comments :
Post a Comment
Your Comment and Question will help to make this blog better...