Converts a string containing an absolute path to a string containing a path relative - Java java.lang

Java examples for java.lang:String Contain

Description

Converts a string containing an absolute path to a string containing a path relative

Demo Code


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

public class Main {


    /**//from  ww w . j a va 2  s .  co m
     * Converts a string containing an absolute path to a string
     * containing a path relative to absPart.
     */
    public final static String relativePath(String path, String absPart) {
        if (path.startsWith(absPart)) {
            path = path.substring(absPart.length());
            if (path.startsWith(File.separator))
                return path.substring(1);
        } // end if
        return path;
    }
}

Related Tutorials