我是否需要处理或忽略OutputStream close()函数触发的IOException?

Jim*_*mmy 5 java io outputstream

在下面的代码中,outPutStream的close函数抛出了我应该捕获的IOException异常.我的问题是我需要处理吗?由于我正在使用移动设备,我想确保释放我使用的所有资源,或者我可以安全地忽略该异常.

//...
OutputStream output = null;
try {
     output = connection.getOutputStream();
     output.write(query.getBytes(charset));
} finally {
     if (output != null) try { 
        output.close(); 
     } catch (IOException e) {
        // Do i need to do something here ?
     }
}
Run Code Online (Sandbox Code Playgroud)

sti*_*vlo 7

如果收盘不起作用,你能做什么?

你唯一能做的就是记录异常,正如@mprabhat建议你可以将引用设置为null来加速GC.