Java URI to Relative URI relativePath(final URI baseURI, final URI pathURI)

Here you can find the source of relativePath(final URI baseURI, final URI pathURI)

Description

Path relative to base.

License

BSD License

Declaration

public static String relativePath(final URI baseURI, final URI pathURI) 

Method Source Code

//package com.java2s;
/**//from w  w  w . ja  va  2  s . co m
 * Copyright (C) 2013 Barchart, Inc. <http://www.barchart.com/>
 *
 * All rights reserved. Licensed under the OSI BSD License.
 *
 * http://www.opensource.org/licenses/bsd-license.php
 */

import java.io.File;

import java.net.URI;

public class Main {
    /**
     * Path relative to base.
     */
    public static String relativePath(final String base, final String path) {
        final URI baseURI = new File(base).toURI();
        final URI pathURI = new File(path).toURI();
        return baseURI.relativize(pathURI).getPath();
    }

    /**
     * Path relative to base.
     */
    public static String relativePath(final URI baseURI, final URI pathURI) {
        return baseURI.relativize(pathURI).getPath();
    }
}

Related

  1. getRelativeURI(URI repositoryXml, URI bundleJar)
  2. getRelativeUri(URI rootURI, File file)
  3. getRelativeURI(URI uri, URI relativeTo)
  4. relativeConfig(URI uri)
  5. relativeFileToURI(File file)
  6. relativeURI(String basePath, String path)
  7. relativize(URI base, URI child)
  8. relativize(URI base, URI child)
  9. relativize(URI base, URI target)