Here you can find the source of isLegalURL(final String url)
Parameter | Description |
---|---|
url | An URL as String |
public static boolean isLegalURL(final String url)
//package com.java2s; /******************************************************************************* * Copyright (c) 2005, 2007 committers of openArchitectureWare 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 * * Contributors://from w w w. j a v a 2 s . c o m * committers of openArchitectureWare - initial API and implementation *******************************************************************************/ import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; public class Main { /** * Proves if the given string is a valid URL. This method tries to open the * URL to check its validity. * * @param url * An URL as String * @return <tt>true</tt> if the string is a valid URL, otherwise * <tt>false</tt>. */ public static boolean isLegalURL(final String url) { if ((url == null) || (url.trim().length() == 0)) { return false; } try { final URL u = new URL(url); u.openConnection(); return true; } catch (final MalformedURLException e) { return false; } catch (final IOException e) { return false; } } }