Here you can find the source of getAbsoluteUrlPathFromFile(String file)
Parameter | Description |
---|---|
file | the file String |
public static String getAbsoluteUrlPathFromFile(String file)
//package com.java2s; //License from project: Apache License import java.net.URL; public class Main { /**//from w ww.ja v a 2 s .c o m * Removes file name from URL string * * @param file the file String * @return the URL String */ public static String getAbsoluteUrlPathFromFile(String file) { String url = getAbsoluteUrlFromFile(file); return url.substring(0, url.lastIndexOf('/')); } /** * Converts a file String to a valid URL String.<br> * Example: <code>index.html</code> converts to <code>file://C:/path/to/file/index.html</code>. * * @param file the file String * @return the URL String */ public static String getAbsoluteUrlFromFile(String file) { if (file == null) { throw new IllegalArgumentException("file must not be null"); } URL url = ClassLoader.getSystemResource(file); if (url == null) { throw new NullPointerException("url from file=" + file + " is null"); } return url.toString(); } }