Java URLConnection - Wann muss ich die connect () -Methode verwenden?
Ich habe ein Problem, die Bedeutung der zu verstehenconnect()
Methode in derURLConnection
Klasse. Im folgenden Code, wenn ich das verwendeconnect()
Methode erhalte ich das gleiche Ergebnis, wenn ich es nicht benutze.
Warum (oder wann) muss ich es verwenden?
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);
}