What's the best way to suppress a runtime console warning in Java?

前端 未结 7 1497
情歌与酒
情歌与酒 2021-02-07 07:15

I am using the getResponseBody() method of the org.apache.commons.httpclient.methods.PostMethod class. However, I am always getting a message written to the console at runtime:

7条回答
  •  無奈伤痛
    2021-02-07 08:04

    to simply 'save' the stderr messages then print them after completion of the main task

    PrintStream origErr = System.err;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream newErr = new PrintStream(baos);
    System.setErr(newErr);
    
    ====== do stuff ======
    
    System.setErr(origErr);
    System.err.print(baos);
    

提交回复
热议问题