程序的功能是,取文件jieguo_guowai.txt的内容与
abroadiplong.txt文件比较个数字,满足条件的,写进abroadregion.txt文件中jieguo_guowai.txt的内容有3700行,而程序读500行生成结果就结束了,这是为什么???
public static void main(String args[])

int j=0; 
try{  
FileReader fr=new FileReader("C:\\cdn\\dns\\jieguo_guowai.txt");
BufferedReader br=new BufferedReader(fr);
 
try{
while(br.ready()){
String line[]=br.readLine().split("\\s+"); 
 
    long iplong=ipToLong(line[0].trim()); 
 
try{ //chinaiptolong.txt文件读
   
FileReader fr1=new FileReader("c:\\cdn\\dns\\abroadiplong.txt");
BufferedReader br1=new BufferedReader(fr1);
try{
while(br1.ready()){
String line1=br1.readLine();

Pattern p1=Pattern.compile("([0-9]{9,10}) ([0-9]{9,10}) (.*)?");
Matcher m1 = p1.matcher(line1); 

while(m1.find())
{

if(iplong<=Long.parseLong(m1.group(2).trim())&&iplong>=Long.parseLong(m1.group(1).trim()))
{
System.out.println(line[0].trim());

log1(line[0].trim()+"\t"+m1.group(3).trim()+"\n","c:\\cdn\\dns\\abroadregion.txt");

}


}

}
}finally{
fr.close();
}
 
}catch(IOException e){
System.out.println();
}
 

    
 
}
}finally{
fr.close();
}
 
}catch(IOException e){
System.out.println();
}
 

System.out.println(j);

}

解决方案 »

  1.   

    这样写呢? 
    String s = null;
    while((s=br.readLine())!=null) {
         
       String line[]=s.split("\\s+"); }
      

  2.   

    你的判断都用while来做的??????????????????????????????????????????
      

  3.   

    while ((str = breader.readLine()) != null)
    我也是这么读的呀,我就没问题的。
    你看看文本里 500行是否有什么特殊的地方,比如多了个回车字符啊什么的。
      

  4.   

    你为什么要关闭两次,那个却不管他呢?
    }finally{ 
    fr.close(); 
    } }catch(IOException e){ 
    System.out.println(); 

        } 
    }finally{ 
    fr.close(); 
      

  5.   

    if(iplong <=Long.parseLong(m1.group(2).trim())&&iplong>=Long.parseLong(m1.group(1).trim())) 
    关闭不是问题的所在,这个语句的原因
      

  6.   

    1.将Exception打印出来,查看原因
    2.abroadiplong.txt大不大,若是很小,完全可以在前期读入内存中,加速匹配时的速度。