java - Do we need to set a process variable to null in a finally block? -
if have following code:
process p = null; bufferedreader br = null; try{ p = runtime.getruntime().exec("ps -ef"); br = new bufferedreader(new inputstreamreader(p.getinputstream())); //do br } catch (exception e) { //handle catch block } { //do need set p = null; }
is p = null required in block or associated streams closed default?
there's no need set process null
, it'd idea explicitly close bufferedreader
in finally
block. or better, if using java 7 or above, consider using try
resources automatically close stream.
Comments
Post a Comment