Java URLConnection - When do I need to use the connect() method?

北战南征 提交于 2019-11-28 09:37:20
Amanda
HttpURLConnection conn = (HttpURLConnection) u.openConnection();

only creates an Object

connect() method is invoked by conn.getInputStream();

swagat

You are not always required to explicitly call the connect method to initiate the connection.

Operations that depend on being connected, like getInputStream, getOutputStream, etc, will implicitly perform the connection, if necessary.

Here's the oracle doc link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!