好象没有,
你可以用String 类的indexof 来实现查找和替换。
如果是一个char,可以用replace

解决方案 »

  1.   

    private String replaceTag(String str, String from, String to)
    {
        int index = 0;
        int pos = 0;
        while((pos = str.indexOf(from, index)) != -1)
        {
            str = str.substring(0, pos) + to + str.substring(pos + from.length());
            index = pos + from.length();
        }    return str;
    }
      

  2.   

    能说得再详细一点吗?我的思路是这样子:先读取文件:
    FileReader f=new FileReader("1.txt");
    BufferedReader br=new BufferedReader(f);
    然后再br.readLine()读出每一行。紧接着应该怎么做我就不懂了。
    能否将所读出的每一行(不含有特定字符的行),先放入一数组中;若遇到含有特定字符的行,经过替换掉特定字符的处理后,再放入数组,然后再将数组的内容写进文件里面去。如果可以的话,又是怎么样写进文件呢?因为文件本身已经有内容了,能够将它的内容先清空掉,然后再写进新的内容呢,具体又是怎么做?关键是最后一步,将内容清空掉,然后再写的这一步。
      

  3.   

    1.生成一个临时文件;
    2.读出每一行的内容,写入一个String类型的变量str;
    3.调用方法str = replaceTag(str, from, to),对str进行字符替换;
    4.把新的str写入临时文件;
    5.重复第二步操作,直到文件结束;
    6.删除原文件;
    7.把临时文件重命名为原文件的名字。
      

  4.   

    //生成一个文件
    String fileName = "C:\\TEMP\TEST.TXT";
    File targetFile = new File(fileName);//如果不存在,就创建一个新文件
    if (!targetFile.getCanonicalFile().exists())
    {
        targetFile.getCanonicalFile().createNewFile();
        System.out.println(targetFile.getCanonicalPath());
    }//打开该文件,并把文件长度置零,即清空
    dataFile = new RandomAccessFile(targetFile, "rw");
    if (dataFile.length() != 0)
    {
        dataFile.setLength(0);
    }//对(ASCII)文件进行写操作
    pw = new PrintWriter(new FileOutputStream(dataFile.getFD()));
    pw.println(***);
      

  5.   

    superyellow(大黄)说的有理,应该用临时文件来做,要是将原文件打开全读出来,再清空写不太好,要是文件很大主麻烦啦。将两个文件同时打开:一个读 -> 替换 -> 一个写,不是很好吗?
    另外,字符的替换用replace('','')就行了。
      

  6.   

    我在做的过程中,又碰到了一个小问题:在取得该目录下面所有的文件时,因为有一些是子目录下面又存在子目录的,怎么样来取得这样文件呢?JAVA当中有没有相应的类、方法可以一次性全部取出该目录下面的全部文件(包括子目录)的?
      

  7.   

    见http://expert.csdn.net/Expert/topic/1815/1815910.xml?temp=.3801081