简体   繁体   中英

Disable System.err

Is there a way to set the stream System.err so everything written to it is ignored? (ie discarded not outputted)

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

You can use System.setErr() to give it a PrintStream which doesn't do anything.

See @dogbane's example for the code.

Just set Error to dommy implementation:

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

You need to have special permission to do that.

RuntimePermission("setIO")

You could redirect the err Stream to /dev/null

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM