日期:2014-05-20  浏览次数:20756 次

读取文本文件时CPU 100% ??奇怪了。
只要调用下面的方法,CPU一下就飙升到100%   ,文件存在,不知道什么问题。且这文件只有一行不到10位的数字,应该不会是溢出什么的吧。

代码中有一处判断文件是否存在的,输出证明此文件是存在的。

代码如下:

public   static   String   readfile(String   url){
        try{
        String   filecontent= " ";
        String   temp=null;
       
        File   readfile=new   File(url);
        if   (readfile.exists()){
        System.out.println( "ok: "+url);
        }
        BufferedReader   read=new   BufferedReader(new   FileReader(readfile));
        temp=read.readLine();
        while(temp!=null){     //
        temp=temp+ "\n ";
        temp=temp+read.readLine();
        }
        read.close();
        filecontent=temp;
        return   filecontent;
        }
        catch(Exception   e){
        e.printStackTrace();
        return   " ";
        }
        }

------解决方案--------------------
while(temp!=null){ //
temp=temp+ "\n ";
temp=temp+read.readLine();
} 木有明白你这么写干啥。 分析楼上的已经说了