When using HttpURLConnection does the InputStream need to be closed if we do not \'get\' and use it?
i.e. is this safe?
HttpURLConnection conn = (Htt
Since Java 7 the recommended way is
try (InputStream is = conn.getInputStream()) {
// read from is
// ...
}
as for all other classes implementing Closable. close() is called at the end of the try {...} block.
Closing the input stream also means you are done with reading. Otherwise the connection hangs around until the finalizer closes the stream.
Same applies to the output stream, if you are sending data.