Java Path to URL pathToURLs(String path)

Here you can find the source of pathToURLs(String path)

Description

path To UR Ls

License

Open Source License

Declaration

public static URL[] pathToURLs(String path) throws MalformedURLException 

Method Source Code

//package com.java2s;
/* /*from w  w  w  . jav a 2 s. co m*/
 * @(#)StringUtil.java 1.0 2004-10-11
 *
 * Copyright 2005 UFIDA Software Co. Ltd. All rights reserved.
 * UFIDA PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

import java.io.File;

import java.net.MalformedURLException;
import java.net.URL;

import java.util.StringTokenizer;

public class Main {
    public static URL[] pathToURLs(String path) throws MalformedURLException {
        StringTokenizer st = new StringTokenizer(path, File.pathSeparator);
        URL[] urls = new URL[st.countTokens()];
        int count = 0;
        while (st.hasMoreTokens()) {
            File file = new File(st.nextToken());
            URL url = null;
            url = file.toURI().toURL();
            if (url != null) {
                urls[count++] = url;
            }
        }
        if (urls.length != count) {
            URL[] tmp = new URL[count];
            System.arraycopy(urls, 0, tmp, 0, count);
            urls = tmp;
        }
        return urls;
    }
}

Related

  1. pathFromURL(final URL url)
  2. pathsMatch(URL realm, URL returnTo)
  3. pathsToURLs(ClassLoader classLoader, String... paths)
  4. pathToURL(String path)
  5. pathToUrl(String path)
  6. pathToURLs(String path)
  7. toTargetURL(String path)
  8. toUrl(final String path)
  9. toURL(String path)