Created
December 21, 2012 20:43
-
-
Save brunoborges/4355670 to your computer and use it in GitHub Desktop.
Proposal for getBasePath() on java.net.URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static URL getBasePath(URL url) throws MalformedURLException { | |
| int lastSlash = url.getFile().lastIndexOf('/'); | |
| if (lastSlash == -1) { | |
| return url; | |
| } | |
| String path = url.getFile().substring(0, lastSlash); | |
| URL basePath = new URL(url.getProtocol(), url.getHost(), url.getPort(), path); | |
| return basePath; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment