System.setErr(PrintStream err) : System « java.lang « Java by API






System.setErr(PrintStream err)

    
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.sql.Timestamp;

public class MainClass {

  public static void main(String[] args) {

    try {
      String FILE = "c:\\systemin.txt";
      FileOutputStream outStr = new FileOutputStream(FILE, true);
      PrintStream printStream = new PrintStream(outStr);

      System.setErr(printStream);

      Timestamp now = new Timestamp(System.currentTimeMillis());
      System.out.println(now.toString() + ": This is text that should go to the file");

      outStr.close();
      printStream.close();
    } catch (FileNotFoundException ex) {
      ex.printStackTrace();
      System.exit(-1);
    } catch (IOException ex) {
      ex.printStackTrace();
      System.exit(-1);
    }
  }
}
           
         
    
    
    
  








Related examples in the same category

1.System.exit(int status)
2.System.in
3.System.in.read()
4.System.out
5.System: arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
6.System: clearProperty(String key)
7.System: console()
8.System: currentTimeMillis()
9.System: getenv(String key)
10.System: getProperty(String name)
11.System.getProperty ("user.dir")
12.System: getProperty(String key, String def)
13.System: getProperties()
14.System.identityHashCode(Object x)
15.System: nanoTime()
16.System: setIn(InputStream in)
17.System: setOut(PrintStream err)
18.System: setProperty(String key, String value)