代码如下
File f=new File("C:/birds_r/basefile");
System.out.println(f.toString().replaceAll("\\", "/"));

解决方案 »

  1.   

    楼主看看Java的API 
    String replaceAll(String regex, String replacement) 
              使用给定的 replacement 字符串替换此字符串匹配给定的正则表达式的每个子字符串。 
    所以楼主的代码应该为:File f=new File("C:/birds_r/basefile");
            System.out.println(f.toString().replaceAll("/", "\\"));
      

  2.   

    呵呵。楼主多试验两次嘛
    不然就看下API啊
      

  3.   

    把"/"替换成"\":File f=new File("C:/birds_r/basefile");
    System.out.println(f.toString().replaceAll("/", "\\"));把"\"替换成"/":File f=new File("C:/birds_r/basefile");
    System.out.println(f.toString().replaceAll("\\\\", "/"));
      

  4.   


    // 1.首先如1楼所说,LZ可能题目意思理解错了,至少应该这样:
    File ff = new File("C:/birds_r/basefile");
    System.out.println(ff.toString().replaceAll("/", "\\"));// 2.如果真的是想将"\\"替换成"/",那么应该这样:
    File ff = new File("C:\\birds_r\\basefile");
    System.out.println(ff.toString().replaceAll("\\\\", "/"));
    // 为什么要用"\\\\"呢,因为"\"在正则表达式是是特殊符号,所以用两个"\"表示"\",在正则表达式中就需要两个"\".
    // 但java中使用两个"\"表示一个"\",所有就要用4个"\"表示2个"\"。