直接用replace把不要的字符串替换为空不就行了。

解决方案 »

  1.   

    public killFuck(InputStream is) throws Exception {
    int i=0;
    String s="";
    byte[] b=new byte[is.available()];
    is.read(b);
    s=new String(b);
    s=replace(s,"Fuck","****");
    System.out.print(s);
    }public String replace(String parentStr,String ch,String rep) {
    int i = parentStr.indexOf(ch);
    StringBuffer sb = new StringBuffer();
    if (i == -1)
    return parentStr;
    sb.append(parentStr.substring(0,i) + rep);
    if (i+ch.length() < parentStr.length())
    sb.append(replace(parentStr.substring(i+ch.length(),parentStr.length()),ch,rep));
    return sb.toString();
    }
    ***********************
    使用:
    String str="If you are Thinking!Please Fuck your dog!";
    InputStream is=new java.io.StringBufferInputStream(str);
    killFuck(is);
      

  2.   

    写入文件就简单了!
    OutputStream os=new FileOutputStream("myTxt.txt");
    PrintStream ps=new PrintStream(os);
    ps.print(s);
    ps.close();
      

  3.   

    写入文件就简单了!
    OutputStream os=new FileOutputStream("myTxt.txt");
    PrintStream ps=new PrintStream(os);
    ps.print(s);
    ps.close();