public static String normalizePath(String path) {
        String[] comps = path.split("/");
        String[] ap = new String[comps.length];
        int j = 0;
        boolean absolute = comps[0].length() == 0;

        for (int i = 0; i < comps.length; ++i) {
            String s = comps[i];

            if (s.equals(".") || s.length() == 0)
                continue;

            if (s.equals("..")) {
                if (j > 0)
                    --j;
            } else
                ap[j++] = s;
        }

        if (j == 0)
            return absolute ? "/" : ".";

        if (absolute)
            path = "/" + ap[0];
        else
            path = ap[0];

        for (int i = 1; i < j; ++i)
            path += "/" + ap[i];

        return path;
    }