InputStream(或者其他流类型) in = null;
然后执行其他语句,再 in = new 、、、、
在in new之前其他语句出exception,这时流没有被打开,也就无需关闭,如果不判断if(null != in) 硬要关闭in就出exception
另外你的代码按如下写会更合理:
if(null != in){
try{
in.flush()
in.close()
in = null
}
catch(IOExection e){}
}
是的,你的new FileReader(file)是一个匿名对象。JVM中对于那些打开了没有关闭的IO文件流,会在不再被使用的情况下,等到下次做Full GC的时候把他们全部回收,尽量少使用这种写法。文章来自:http://blog.csdn.net/kongxx/article/details/6405914