Do I need close InputStream of HttpUrlConnection if I never call getInputStream?

Viewed 28

The scenario is I only need to read some values from the HTTP response header. So I never called the httpUrlConnection.getInputStream() or httpUrlConnection.getContentLength().

Do I need add httpUrlConnection.getInputStream().close(); ?

    HttpURLConnection urlConnection = null;
    try {
        URL url = new URL(urlString);
        urlConnection = (HttpURLConnection) url.openConnection();
        String dateStr = urlConnection.getHeaderField("Date");
        Date date =
                new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US).parse(dateStr);
        long timeMillis = date.getTime();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (urlConnection != null) {
            urlConnection.disconnect();
        }
    }
0 Answers
Related