In a very usual operation of parsing JSON, we do something like this
StringBuilder sb = new StringBuilder();
BufferedReader br = null;
try {
URL requestUrl = new URL(url);
URLConnection con = requestUrl.openConnection();
br = new BufferedReader(new InputStreamReader(con.getInputStream()));
int cp;
try {
while ((cp = br.read()) != -1) {
sb.append((char) cp);
}
}
catch(Exception e){
}
}catch (MalformedURLException e){
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
if(br != null){
try{
br.close();
}catch (IOException e){
e.printStackTrace();
}
}
}
Here I am just closing the buffered reader. Is this enough, or I should close the Input stream as well ?