1. replaceAll("\\", "\\\\");2. abc\\adf -> abc\adf

解决方案 »

  1.   

    temp=temp.replaceAll("\\\\","\\\\");
    注意"\"既是字符串转移符,同时有时规则表达式的转移符,所以第一个参数被转了两遍。
    再注意replaceAll的第一个参数是规则表达式,而不是一般的字符串。
      

  2.   

    这里面涉及到转义符在string里,以及replaceAll实际内部处理使用的是正则表达式又涉及到转义修正代码temp=temp.replaceAll("\\\\","\\\\\\\\");
      

  3.   

    把那个算法贴出来让大家笑笑  :)
    public void formatPath() {
            String temp = "";
            for (int i = 0; i < path.length(); i++) {
                if (path.charAt(i) == '\\') {
                    temp = temp + "\\";
                } else {
                    temp = temp + path.charAt(i);
                }
            }
            path = temp;
        }