我要在html文件中找出相对路径“./././././error.jsp”或“././error.jsp”(几级目录不确定)转换成绝对路径“c:\\Tomcat 5.5\\webapps\\test002\\”,该怎么实现这个功能,能提供思路也好,如果有那位兄弟有相关的代码那就太感谢了,谢谢!

解决方案 »

  1.   

    读取整个文件,变成一个String后:System.out.println(str.replaceAll("(\\./)*error\\.jsp", "C:\\\\error.jsp"));
      

  2.   

    可是,如果我的相对路径有“a/b/c/d/e.html”和“a/b.html”两种。那么我要转换的路径就是“c:\Tomcat 5.5\webapps\test002\a\b\d\.html”和"c:\Tomcat 5.5\webapps\test002\a\b.html",这样子的话该怎么样实现?
      

  3.   

    "c:/Tomcat 5.5/webapps/test002/" + yourPath
      

  4.   

    public static String rep(String str, String pattern, String replace) { {
    int s = 0;
    int e = 0;
    if (str != null) {
    StringBuffer result = new StringBuffer();
    while ((e = str.indexOf(pattern, s)) >= 0) {
    result.append(str.substring(s, e));
    result.append(replace);
    s = e + pattern.length();
    }
    result.append(str.substring(s));
    return result.toString();
    }
    return str;