Disable System.err

前端 未结 4 2178
没有蜡笔的小新
没有蜡笔的小新 2021-02-18 22:58

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

相关标签:
4条回答
  • System.setErr(new PrintStream(new OutputStream() {
        public void write(int b) {
        }
    }));
    
    0 讨论(0)
  • 2021-02-18 23:30

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

    See @dogbane's example for the code.

    0 讨论(0)
  • 2021-02-18 23:42

    You could redirect the err Stream to /dev/null

    OutputStream output = new FileOutputStream("/dev/null");
    PrintStream nullOut = new PrintStream(output);
    System.setErr(nullOut);
    
    0 讨论(0)
  • 2021-02-18 23:48

    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")
    
    0 讨论(0)
提交回复
热议问题