Redirect output, error report to files instead of console
import java.util.*;
import java.lang.*;
/* Program to redirect output and error report to files instead of console */
import java.io.*;
class errorMessage
{
public static void main(String[] args)
{
try{
PrintStream st = new PrintStream(new FileOutputStream("error.txt"));
PrintStream ps = new PrintStream(new FileOutputStream("output.txt"));
System.setOut(ps);
System.setErr(st);
System.out.println("output redirected to file");
}catch(FileNotFoundException e){
System.out.println("exception caught");
}
System.out.println(args[2]);
}
}