Java Relative Path Get relativizePath(String parent, String child)

Here you can find the source of relativizePath(String parent, String child)

Description

relativize Path

License

Open Source License

Declaration

public static String relativizePath(String parent, String child) 

Method Source Code

//package com.java2s;
import java.io.File;

public class Main {
    public static String relativizePath(String parent, String child) {
        // Fix for SCM-772. Compare FixedGitStatusConsumer.
        if (parent != null && child != null) {
            if (parent.equals(child)) {
                return "";
            }/*from  ww w .j a  v  a  2 s . co  m*/
            if (!parent.endsWith(File.separator)) {
                parent += File.separator;
            }
            if (child.startsWith(parent)) {
                child = child.substring(parent.length());
                if (child.startsWith(File.separator)) {
                    child = child.substring(File.separator.length());
                }
            }
        }
        return child;
    }
}

Related

  1. relativize(String path)
  2. relativize(String path)
  3. relativize(String path, String base)
  4. relativizePath(File from, File to)
  5. relativizePath(final File path, final File base)
  6. relativizePathSegments(String[] srcSegments, String[] destSegments)