Here you can find the source of createURL(String src, File basedir)
Parameter | Description |
---|---|
src | a URL or a file path |
basedir | base directory for relative file paths |
Parameter | Description |
---|---|
MalformedURLException | an exception |
public static URL createURL(String src, File basedir) throws MalformedURLException
//package com.java2s; //License from project: LGPL import java.io.File; import java.net.MalformedURLException; import java.net.URL; public class Main { /**//from w w w.j a v a 2s . c o m * Converts a string to a URL. If it doesn't form a valid URL as is, it will * be treated as a file and converted to a file: URL. Relative file paths * will be interpreted, relative to basedir, and converted to absolute form. * * @param src a URL or a file path * @param basedir base directory for relative file paths * @return URL-equivalent of src * @throws MalformedURLException */ public static URL createURL(String src, File basedir) throws MalformedURLException { URL srcURL; try { srcURL = new URL(src); } catch (MalformedURLException e) { File srcFile = new File(src); if (!srcFile.isAbsolute()) { srcFile = new File(basedir, src); } srcURL = srcFile.toURI().toURL(); } return srcURL; } }