See Also: URLConnection Members
A connection to a URL for reading or writing. For HTTP connections, see Java.Net.HttpURLConnection for documentation of HTTP-specific features.
For example, to retrieve ftp://mirror.csclub.uwaterloo.ca/index.html:
java Example
URL url = new URL("ftp://mirror.csclub.uwaterloo.ca/index.html"); URLConnection urlConnection = url.openConnection(); InputStream in = new BufferedInputStream(urlConnection.getInputStream()); try { readStream(in); finally { in.close(); } }
URLConnection must be configured before it has connected to the remote resource. Instances of URLConnection are not reusable: you must use a different instance for each connection to a resource.