读书人

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

发布时间: 2012-02-01 16:58:19 作者: rapoo

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

读书人网 >J2SE开发

热点推荐