Java Data Type Tutorial - Java System.setErr(PrintStream err)








Syntax

System.setErr(PrintStream err) has the following syntax.

public static void setErr(PrintStream err)

Example

In the following code shows how to use System.setErr(PrintStream err) method.

//ww w .j a v a 2s . co m

import java.io.FileOutputStream;
import java.io.PrintStream;

public class Main {

   public static void main(String[] args) throws Exception {

     FileOutputStream f = new FileOutputStream("file.txt");
        
     System.setErr(new PrintStream(f));

     System.err.println("This will get redirected to file from java2s.com");
   }
}