import java.io.*; public class RedirectErrorStreamToLog { public static void main(String[] args) throws FileNotFoundException { PrintStream errorLog = new PrintStream(new File("error.log")); System.setErr(errorLog); // generate an error int result = 10 / 0; } }
import java.io.*; public class RedirectErrorStreamToConsole { public static void main(String[] args) { System.setErr(System.out); // generate an error int result = 10 / 0; } }Package library: java.util