Here you can find the source of getURLConnection(URL url)
Parameter | Description |
---|---|
url | URL to open connection to |
Parameter | Description |
---|---|
MalformedURLException | if the url is null |
IOException | if there is a problem accessing the resource specified by the url |
public static URLConnection getURLConnection(URL url) throws MalformedURLException, IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2006, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * /*from ww w. ja va2s . co m*/ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ import java.io.IOException; import java.net.*; public class Main { /** * Returns a URL connection that an input stream can be obtained from. The * URL Connection can handle urls of a variety of types including files, jar * files and remote urls. * <p> * NOTE: If the connection is of type {@link JarURLConnection} the zip file * should be independantly closed using {@link JarURLConnection#getJarFile()}.close() * https://bugs.eclipse.org/bugs/show_bug.cgi?id=326263 * </p> * * @param url URL to open connection to * @return the url connection * @throws MalformedURLException if the url is null * @throws IOException if there is a problem accessing the resource specified by the url */ public static URLConnection getURLConnection(URL url) throws MalformedURLException, IOException { if (url == null) { throw new MalformedURLException("URL specified is null"); //$NON-NLS-1$ } URLConnection connection = url.openConnection(); if (connection instanceof JarURLConnection) { connection.setUseCaches(false); } return connection; } }