public String simplifyPath(String path){
    if (path == null || path.length() == 0)
        return "/";
    
    Stack<String> stack = new Stack<String>();
    for (String s : path.split("/")){
        if (s.length() == 0 || s.equals("."))
            continue;
        else if (s.equals("..")){
            if (!stack.isEmpty())
                stack.pop();
        } else 
            stack.push(s);
    }
    
    if (stack.isEmpty())
        return "/";
    
    StringBuffer sb = new StringBuffer("");
    while (!stack.isEmpty()){
        sb.insert(0, stack.pop());
        sb.insert(0, "/");
    }
    return sb.toString();
  }