Here you can find the source of getRelativeURI(String href)
public static String getRelativeURI(String href)
//package com.java2s; import java.io.*; import java.net.URL; import java.net.MalformedURLException; public class Main { /**//from w w w. j a va 2 s . c o m * the path separator for an URI */ private static final char HREF_PATH_SEP = '/'; /** * Returns the relative URI of the href argument * * @return the relative URI the given href **/ public static String getRelativeURI(String href) { if (href == null) return href; int idx = -1; // -- check for URL try { // -- try to create a new URL and see if MalformedURLExcetion is // -- ever thrown new URL(href); idx = href.lastIndexOf(HREF_PATH_SEP); } catch (MalformedURLException muex) { // -- The following contains a fix from Shane Hathaway // -- to handle the case when both "\" and "/" appear in filename int idx2 = href.lastIndexOf(HREF_PATH_SEP); idx = href.lastIndexOf(File.separator); if (idx2 > idx) idx = idx2; } if (idx >= 0) return href.substring(idx + 1); return href; } }