Here you can find the source of relativize(String path)
public static String relativize(String path)
//package com.java2s; //License from project: Open Source License import java.io.*; import java.util.regex.Pattern; public class Main { public static String relativize(String path) { String[] split = path.split(Pattern.quote(File.separator)); StringBuilder out = new StringBuilder(); int skip = 0; int len = split.length - 1; for (int i = len; i >= 0; i--) { if (skip > 0) skip--;//from www . j ava 2 s. co m else { String arg = split[i]; if (arg.equals("..")) skip++; else out.insert(0, arg + (i == len ? "" : File.separator)); } } return out.toString(); } }