Java Path Relative Get getRelativePath(@Nullable File projectFile, @Nullable File rootFile)

Here you can find the source of getRelativePath(@Nullable File projectFile, @Nullable File rootFile)

Description

get Relative Path

License

Mozilla Public License

Declaration

@Nullable
    public static String getRelativePath(@Nullable File projectFile,
            @Nullable File rootFile) 

Method Source Code

//package com.java2s;
//     The contents of this file are subject to the Mozilla Public License

import javax.annotation.Nullable;
import java.io.File;

public class Main {
    @Nullable
    public static String getRelativePath(@Nullable File projectFile,
            @Nullable File rootFile) {
        String returnPath = null;

        if (projectFile != null && rootFile != null) {
            returnPath = getRelativePath(projectFile.getAbsolutePath(),
                    rootFile.getAbsolutePath());
        }/*from ww w  .  j  a v a 2 s .  com*/

        return returnPath;
    }

    @Nullable
    public static String getRelativePath(
            @Nullable String projectFileString,
            @Nullable File projectRootFile) {
        String returnPath = null;

        if (projectFileString != null && projectRootFile != null) {
            returnPath = getRelativePath(projectFileString,
                    projectRootFile.getAbsolutePath());
        }

        return returnPath;
    }

    @Nullable
    public static String getRelativePath(@Nullable File projectFile,
            @Nullable String projectRoot) {
        String returnPath = null;

        if (projectFile != null && projectRoot != null) {
            returnPath = getRelativePath(projectFile.getAbsolutePath(),
                    projectRoot);
        }

        return returnPath;
    }

    @Nullable
    public static String getRelativePath(@Nullable String string,
            @Nullable String projectRoot) {
        String returnPath = null;

        if (string != null && projectRoot != null
                && string.startsWith(projectRoot)) {
            returnPath = string.substring(projectRoot.length()).replace(
                    '\\', '/');
        }

        return returnPath;
    }
}

Related

  1. getRelativePath(File a, File b, String pathSep)
  2. getRelativePath(File ancestor, File file)
  3. getRelativePath(File base, File absoluteFile)
  4. getRelativePath(File base, File file)