只要调用下面的方法,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 "";
     }
    }

解决方案 »

  1.   

    while(temp!=null){  //
         temp=temp+"\n";
         temp=temp+read.readLine();
         }这个有问题,只要有一行数据,temp永远不可能为空,死循环了,temp=read.readLine();
      

  2.   

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

  3.   

    楼上分析的有道理,是死循环了,你是想把文件里的东西放到变量里面,多设一个变量就解决问题了。
    String result="";
    while(temp!=null){  //
         result=temp+"\n";
         temp=read.readLine();
         }
    return result;
    这样不会死循环了吧