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

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -