To redirect or save an error into file

This example demonstrates how you can solve the problem of redirecting or sending or saving your exceptions or errors into a file.

Example 1:
import java.io.*;

class A3{
    public static void main(String[] args) throws IOException{
        PrintStream ps=new PrintStream(new FileOutputStream("error.txt"));
        System.setErr(ps);//setErr, setIn
        System.out.println(args[0]);
    }
}

Example 2:
import java.io.*;

class A4{
    public static void main(String[] args){
        try{
        PrintStream ps=new PrintStream(new FileOutputStream("error4.txt"));
        System.setErr(ps);//setErr, setIn
        System.out.println(args[0]);
        }catch(Exception e){
        System.err.println(e);
        }
    }
}