Java IO Tutorial - Java PrintStream.setError()








Syntax

PrintStream.setError() has the following syntax.

protected void setError()

Example

In the following code shows how to use PrintStream.setError() method.

//ww  w.  j a  v  a  2 s .  c o  m

import java.io.*;

public class Main extends PrintStream {

   public Main(OutputStream out) {
      super(out);
   }

   public static void main(String[] args) {
      byte c[] = {70, 71, 72, 73, 74, 75, 76};

      
      Main ps = new Main(System.out);

      // write bytes 1-3
      ps.write(c, 1, 3);

      // flush the stream
      ps.flush();

      // set an internal error
      ps.setError();
   }
}

The code above generates the following result.