Java Path Relative nio relativePath(String input, String mainurl)

Here you can find the source of relativePath(String input, String mainurl)

Description

Compute sub directory of given input, relative to main module.

License

Open Source License

Parameter

Parameter Description
input a parameter
mainurl a parameter

Return

a relative path

Declaration

public static String relativePath(String input, String mainurl) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {
    /**/*from www  .  j a  v  a 2  s.  com*/
     * Compute sub directory of given input, relative to main module.
     * @param input
     * @param mainurl
     * @return a relative path
     */
    public static String relativePath(String input, String mainurl) {
        Path inputPath = Paths.get(input);
        Path rootPath = Paths.get(mainurl);

        Path relativize = rootPath.getParent().relativize(inputPath.getParent());
        return relativize.toString();
    }
}

Related

  1. getRelativePath(String fullPath, String homeFolderPath)
  2. getRelativePath(String relativePathFile)
  3. getSourceFileRelativePath(Class declaringClass)
  4. isRelativePath(Path baseDir, Path file)
  5. isRelativized(final Path base, final String successor)
  6. relativePathTo(Path path, Path basePath)
  7. relativize(Path absoluteDirectory, Path subDirectory)
  8. relativize(Path target, Collection paths)
  9. relativizeAndNormalizePath(final String baseDirectory, final String path)