• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is there any need to close the streams which are opened while executing a process?

 
Kumara Swamy
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have the following snippet of code.

Process p = Runtime.getRuntime().exec(strCommand);
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
String s = null;
while ( (s = stdInput.readLine()) !=null ){

}
while ((s = stdError.readLine()) != null){
}


Is there any need to close the streams or will they automatically close?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's generally a good idea to close them.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!