2 seelye seelye 于 2014.09.11 17:43 提问

java 封装流关闭的疑问

BufferedWriter writer = null;
try {
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath), "UTF-8"));
writer.write("

"
+ context);
writer.flush();
logger.debug("写文件成功,[filePath=" + filePath + "]");
} finally {
if (writer != null) {
writer.close();
}
}

为什么这段代码,只用writer.close();就把流关闭了,
new OutputStreamWriter(new FileOutputStream(filePath), "UTF-8")这些new出来的流对象为什么不用关闭?

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!