URLConnection
クラスのconnect()
メソッドの意味を理解するのに問題があります。次のコードで、connect()
メソッドを使用する場合、私はそれを使用しない場合と同じ結果が得られます。Java 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);
}
かなり正しいによって呼び出されるオブジェクトを作成します。 Downvoterは説明してください。 +1 – EJP