クラスのconnect()
メソッドの意味を理解するのに問題があります。URLConnection
次のコードでは、connect()
メソッドを使用すると、使用しなくても同じ結果が得られます。
なぜ (またはいつ) 使用する必要があるのですか?
URL u = new URL("http://example.com");
HttpURLConnection conn = (HttpURLConnection) u.openConnection();
conn.connect();//with or without it I have the same result
InputStream in = conn.getInputStream();
int b;
while ((b = in.read()) != -1) {
System.out.write(b);
}