String里就又这么一个成员函数.replace()就可以啊.>你试一试

解决方案 »

  1.   

    replaceAll
    public String replaceAll(String regex,
                             String replacement)
    Replaces each substring of this string that matches the given regular expression with the given replacement. 
    An invocation of this method of the form str.replaceAll(regex, repl) yields exactly the same result as the expression Pattern.compile(regex).matcher(str).replaceAll(repl)Parameters:
    regex - the regular expression to which this string is to be matched 
    Returns:
    The resulting String 
    Throws: 
    PatternSyntaxException - if the regular expression's syntax is invalid 
    NullPointerException - if regex is null
    Since: 
    1.4 
    See Also:
    Pattern例子:
    String ss = "abcdsakhfdkahg";
    out.println(ss);
    String xx = ss.replaceAll("a","yy");
    out.println(xx); 
      

  2.   

    哦,对不起,我没有把意思说明白,java中打开文件的路径必须是“/”,
    例如:d:/MyJava/one.txt
    而我用函数的到的是“\”,例如:d:\MyJava\one.txt 。这个“\”比较特殊,我如何转换?
    帮我写个简单例子!谢谢
      

  3.   

    import java.util.*;public class ReplaceTest{
    public static void main(String[] args) throws Exception{ String str = "d:/MyJava/one.txt"; System.out.println(str.replace('/','\\'));   }        
    }