Here you can find the source of getParentURI(URI uri)
public static URI getParentURI(URI uri)
//package com.java2s; /***************************************************************************** * Copyright (c) 2006-2013, Cloudsmith Inc. * The code, documentation and other materials contained herein have been * licensed under the Eclipse Public License - v 1.0 by the copyright holder * listed above, as the Initial Contributor under such license. The text of * such license is available at www.eclipse.org. *****************************************************************************/ import java.net.URI; import java.net.URISyntaxException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; public class Main { public static URI getParentURI(URI uri) { if (uri == null) return uri; IPath uriPath = Path.fromPortableString(uri.getPath()); if (uriPath.segmentCount() == 0) return null; uriPath = uriPath.removeLastSegments(1).addTrailingSeparator(); try {//from w w w . j a va2s. c om return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uriPath.toPortableString(), uri.getQuery(), uri.getFragment()); } catch (URISyntaxException e) { // Shouldn't happen since we started with a valid URI // return null; } } }