当前位置: 代码迷 >> Java相关 >> 高手帮忙看下啊
  详细解决方案

高手帮忙看下啊

热度:196   发布时间:2009-08-12 22:22:37.0
高手帮忙看下啊
import java.io.*;
public class IODemo4
{
     
    public static void main(String[] args)
    {
        try
        {  
         
            File file        = new File ("f:\\java\\source.txt");
            int sizeL         = (int)file.length();  
            int chars_read   =   0;   
            
                BufferedReader in =new BufferedReader( new FileReader("f:\\java\\source.txt"));
                 
            char[]   data   =   new   char[sizeL];   
            while(in.ready())     
             {
            chars_read  +=   in.read(data,   chars_read,   sizeL   -   chars_read);        
            }
              
              
             String   temp="";   
              
             for(int   j=0;j<chars_read;j++)   
              temp+=data[j];   
             String   newtemp=temp.replace("tihuan","g");  
               
              in.close();
               
                  
                  

                  
                  
                  
                 
            PrintWriter out =new PrintWriter(
                new FileWriter("f:\\java\\destnation1.txt"));
                out.println(newtemp);

            
            out.close();
        }
        catch(Exception e) {}
    }
}

为什么字符没有替换呢?
----------------解决方案--------------------------------------------------------
把 替换字符和要替换的字符 弄混了,
----------------解决方案--------------------------------------------------------
细心啊
----------------解决方案--------------------------------------------------------
  相关解决方案