2011-05-09 9 views
14

¿Hay alguna forma de establecer la secuencia System.err para que se ignore todo lo escrito en ella? (es decir, no descartada)Desactivar System.err

Respuesta

33
System.setErr(new PrintStream(new OutputStream() { 
    public void write(int b) { 
    } 
})); 
+6

He encontrado otra forma: System.err.close(); – elou

18

Puede usar System.setErr() para proporcionarle un PrintStream que no hace nada.

Vea el ejemplo de @ dogbane para el código.

2

puede redirigir la corriente del err a /dev/null

OutputStream output = new FileOutputStream("/dev/null"); 
PrintStream nullOut = new PrintStream(output); 
System.setErr(nullOut); 
+1

esto es * nix específico, sin embargo. – asgs

+1

Nota: en Windows, use "NUL:" en lugar de "/ dev/null". – dogbane

+0

/dev/null no existe en Windows (aunque puedes usar NUL) –

4

error Sólo hay que establecer a Dommy aplicación:

System.setErr(new PrintStream(new OutputStream() { 
      @Override 
      public void write(int arg0) throws IOException { 
       // keep empty 
      } 
     })); 

Es necesario tener un permiso especial para hacerlo.

RuntimePermission("setIO")