首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

读取文本文件时CPU 100% ?奇怪了。解决思路

2012-02-01 
读取文本文件时CPU 100% ??奇怪了。只要调用下面的方法,CPU一下就飙升到100%,文件存在,不知道什么问题。且这

读取文本文件时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();
} 木有明白你这么写干啥。 分析楼上的已经说了

热点排行